我有一个net.tcp服务,我想让其他平台(特别是PHP)可以访问它。为此,我使用http绑定。
我用:
创建一个http端点ServiceHost svh = new ServiceHost(typeof(MyService));
var httpLocation = "http://" + address + ":4041";
svh.AddServiceEndpoint(typeof(IMyService), new WebHttpBinding(WebHttpSecurityMode.None),
httpLocation);
svh.AddServiceEndpoint(
ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexHttpBinding(),
httpLocation + "/mex"
);
svh.Open();
现在,当我试图通过访问http://localhost:4041
来浏览服务时,我得到了:
<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none">
<Code>
<Value>Sender</Value>
<Subcode>
<Value xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</Value>
</Subcode>
</Code>
<Reason>
<Text xml:lang="en-US">
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
</Text>
</Reason>
我做错了什么?
答案 0 :(得分:1)
浏览时,请确保包含.svc
或.asmx
的完整路径以及尾随?wsdl
。
localhost:4041/ServiceVirtualDirectory/Service.svc?wsdl
答案 1 :(得分:1)
您是否尝试过访问http://localhost:4041/MyService.svc?wsdl
?
不确定您的服务是否符合REST设计,这就是您使用WebHttpBinding的原因。
如果您的服务实际上是REST-ful,那么它的格式就是
http://localhost:4041/MyService.svc/MyMethod/MyData
您应该在浏览器上看到结果。基于this ASP.NET线程,您需要附加WebHttpBehavior
。
如果您的服务不是REST-ful,您应该根据您的要求考虑BasicHttpBinding
(使用常规SOAP消息)或其表兄弟(参见this SO线程)。
希望这有帮助。