編輯: 我已將編輯添加到我嘗試尋找解決方案的代碼中,仍然錯誤相同。服務客戶端通信中的ContractFilter不匹配錯誤
下面的文本塊整體的觀點是:
的WCF服務器無法與Objective-C的客戶 設置[OperationContract(ProtectionLevel = ProtectionLevel.None)]
,[ServiceContract(Name = "IServer", Namespace = "http://tempuri.org/")]
和[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
未解決該錯誤消息,商談。詳細配置如下所示。
============================================== ==================================== 因此,我創建了一項服務並將其上傳到服務器
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>
這裏是服務代碼:
[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!";
}
}
客戶端是在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];
當我們試圖打電話給我們得到了美孚()方法:
<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>
有誰知道如何解決這個問題?
我已經完成了關於這個問題的大部分主題,但所有的解決方案都未能解決我們的具體情況。