自我托管的WCF服务不能通过WCFTestClient测试
我正在尝试使用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将其准备好进行测试。
我怀疑你的MEX端点有问题。您目前只指定一个相对地址(“MEX”) - 但没有基址为您服务定义HTTP ......
我会建议:
- 要么定义基地地址,然后“上面”的仅使用相对地址 - 您经常和你的MEX终结
OR:
- 定义地址为充分,完整的地址 - 不仅适用于您的常规端点,而且也适用于MEX端点。
因此改变你的配置是这样的:
<service name ="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehavior">
<endpoint
address="http://localhost:2303/MyService"
binding="basicHttpBinding"
contract="MyService.IMyService"/>
<endpoint name="mexpoint"
address="http://localhost:2303/MyService/mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
,然后我希望你应该能得到你的元数据,从而连接到您服务!
真棒!那工作。谢谢马克。但是,现在它在WcfTestClient中工作,我试着检查当我在浏览器窗口中点击URL http:// localhost:2303/MyService时是否可以看到某些内容。我收到一个HTTP 400错误的请求。任何指针在这里? – user20358
另外,对于cassini托管的服务,我们不需要指定基地址。该配置是我从卡西尼托管的wcf服务中提取出来的。卡西尼是否在封面上添加了什么? – user20358
@ user20358:这是一个** SOAP **服务 - 您无法从浏览器“点击”SOAP服务 - 您的浏览器不会与SOAP进行通信。您应该可以通过转到http:// localhost:2303/MyService/mex?WSDL' –
您是否正在运行Windows 7?
尝试运行:
netsh http add urlacl url=http://+:2303/MyService user=DOMAIN\user
是的,我使用Win 7.另外,我为DOMAIN \ user放置了什么..我在没有连接到任何域的家用PC上运行这个。用户是否需要成为登录用户?..我想它确实......是吗? – user20358
当我尝试通过winforms客户端运行它时,该服务起作用,所以我知道该服务正在运行。问题是如何使用WcfTestClient将其准备好进行测试。 – user20358
命令netsh http add urlacl url = http:// +:2303/MyService user = PCNAME \ mylogin给了我这个:网址保留添加失败,错误:87 – user20358
尝试运行你的视觉工作室担任管理员。然后你不需要手动运行命令(url = http:// +:2303/MyService user = PCNAME \ mylogin)
我正在运行它作为管理员。 – user20358
offtopic但你有类相同的命名空间,困惑下来,我同意行 – V4Vendetta
完美元素的名称,但是这是一个研究项目,所以我顺其自然。 – user20358