我正在嘗試使用WCFTestClient來測試自己託管的wcf服務。我得到一個錯誤,像這樣:自我託管的WCF服務不能通過WCFTestClient測試
Error: Cannot obtain Metadata from http://localhost:2303/MyService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:2303/MyService Metadata contains a reference that cannot be resolved: 'http://localhost:2303/MyService'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:2303/MyService . The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..HTTP GET Error URI: http://localhost:2303/MyService There was an error downloading 'http://localhost:2303/MyService'. The request failed with HTTP status 400: Bad Request.
我的項目結構如下
-
充當主機
- 控制檯應用程序
- 服務合同
- 服務實現
這裏有我的服務實施和合同類,它們分屬於兩個獨立的項目。
namespace MyService
{
public class MyService : IMyService
{
public string GetGreeting(string name)
{
return "Hello " + name;
}
public string GetYelling(string name)
{
return "What the hell " + name + "!!";
}
}
}
namespace MyService
{
[ServiceContract]
public interface IMyService
{
[OperationContract]
string GetGreeting(string name);
[OperationContract]
string GetYelling(string name);
}
}
這是控制檯應用程序
namespace MyWCFHost
{
class Program
{
static void Main(string[] args)
{
ServiceHost serviceHost = new ServiceHost(typeof(MyService.MyService), new Uri("http://localhost:2303"));
serviceHost.Open();
Console.WriteLine("MyService is running...");
Console.ReadKey();
serviceHost.Close();
}
}
}
這是配置文件
<configuration>
<system.serviceModel>
<services>
<service name ="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehavior">
<endpoint address="http://localhost:2303/MyService" binding="basicHttpBinding" contract="MyService.IMyService"/>
<endpoint address="mex" binding="mexHttpBinding" name="mexpoint" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyService.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我在做什麼錯?
感謝您的時間...
編輯
的服務工作,當我嘗試通過一個WinForms客戶端來運行它,所以我知道該服務工作。問題是如何使用WcfTestClient將其準備好進行測試。
offtopic但你有類相同的命名空間,困惑下來,我同意行 – V4Vendetta
完美元素的名稱,但是這是一個研究項目,所以我順其自然。 – user20358