我正在从我的iphone应用程序请求WCF方法。但我总是得到一个falutString作为回应。
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<soapenv:Envelope \n"
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" \n"
"xmlns:tem=\"http://tempuri.org/\" \n"
"xmlns=\"http://WssMobileService.Model/2012/ServiceContractDslModel\">\n"
"<soapenv:Header/>\n"
"<soapenv:Body>\n"
"<tem:GetCompanies>\n"
"<tem:ReqLogin>\n"
"<UserName>%@</UserName>\n"
"<Password>%@</Password> \n"
"</tem:ReqLogin>\n"
"</tem:GetCompanies>\n"
"</soapenv:Body>\n"
"</soapenv:Envelope>\n",username,password];
NSURL *url = [NSURL URLWithString:kMainURL];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/WssServiceContract/GetCompanies" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
url 出现
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/"
xmlns="http://WssMobileService.Model/2012/ServiceContractDslModel">
<soapenv:Header/>
<soapenv:Body>
<tem:GetCompanies>
<tem:ReqLogin>
<UserName>something</UserName>
<Password>something</Password>
</tem:ReqLogin>
</tem:GetCompanies>
</soapenv:Body>
</soapenv:Envelope>
这是我收到的请求:
<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="en-US">The message with Action 'http://tempuri.org/WssServiceContract/GetCompanies' 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>
我看到几个StackOverflow解决方案,但似乎没有任何帮助。