[英]ContractFilter mismatch error on service client communication
EDIT: I have added edits to the code that i made to try and find a solution, still the error is the same. 编辑:我已经添加了对我尝试查找解决方案所做的代码的编辑,仍然错误是相同的。
The point of the whole block of text below is: 下面整个文本的重点是:
The WCF server cannot talk with the Objective-C client Setting [OperationContract(ProtectionLevel = ProtectionLevel.None)]
, [ServiceContract(Name = "IServer", Namespace = "http://tempuri.org/")]
and [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
didn't resolve the error message. WCF服务器无法与Objective-C客户端设置
[OperationContract(ProtectionLevel = ProtectionLevel.None)]
, [ServiceContract(Name = "IServer", Namespace = "http://tempuri.org/")]
和[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
无法解决错误消息。 Detailed configuration is shown below. 详细配置如下所示。
================================================================================== So i created a service and uploaded it to a server ================================================== ================================所以我创建了一个服务并将其上传到服务器
the web.config file goes as follows: web.config文件如下所示:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Windows"/>
<customErrors mode="Off"></customErrors>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
<services>
<service behaviorConfiguration="AppComService.Service1Behavior" name="AppComService.Service">
<endpoint address="" binding="basicHttpBinding" contract="AppComService.ComService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AppComService.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
And here is the service code: 这是服务代码:
[ServiceContract(Name = "IServer", Namespace = "http://tempuri.org/")]
public interface ComService
{
[OperationContract(ProtectionLevel = ProtectionLevel.None)]
string Foo();
// TODO: Add your service operations here
}
... ...
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Service : ComService
{
public string Foo()
{
return "foo!";
}
}
The client is done in Objective-c, and the configuration goes as follows: 客户端是在Objective-c中完成的,配置如下:
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<SOAP-ENV:Envelope \n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
"<SOAP-ENV:Body> \n"
"<Login xmlns=\"http://tempuri.org/\"><username>username</username><password>password</password>"
"</Login> \n"
"</SOAP-ENV:Body> \n"
"</SOAP-ENV:Envelope>"];
NSURL *url = [NSURL URLWithString:@"http://api.tagastic.com/Service.svc/foo"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%i", (int)[soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/ComService/foo" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
when we try to call the Foo() method we get: 当我们尝试调用Foo()方法时,我们得到:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">
a:ActionNotSupported
</faultcode>
<faultstring xml:lang="hr-HR">
The message with Action 'http://tempuri.org/ComService/foo' 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).
</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
Does anyone know how to fix this? 有谁知道如何解决这一问题?
I have already run through most of the topics regarding this matter, but all of the solutions failed to to solve our specific situation. 我已经遍历了有关此问题的大多数主题,但是所有解决方案都无法解决我们的具体情况。
So in the end i needed to do a few things: first added the web invoke to the metoods: 因此,最后我需要做一些事情:首先将网络调用添加到方法中:
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Foo")]
then i added elements to the web.config: 然后我将元素添加到web.config中:
<service behaviorConfiguration="AppComService.Service1Behavior" name="AppComService.Service">
<endpoint address="../Service.svc"
binding="webHttpBinding"
contract="AppComService.ComService"
behaviorConfiguration="webBehaviour" />
</service>
...
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
and that was it. 就是这样。 the client can now access the service.
客户端现在可以访问该服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.