2013-11-26 33 views
0

呃。我已經在SOF上看到了一些類似的問題,但到目前爲止,這些解決方案都沒有爲我工作。從iOS連接到WCF

我想將iOS7客戶端連接到WCF Web服務。讓我繼續指出,我沒有寫WCF服務,也沒有寫過WCF服務 - 所以我很WCF很愚蠢。據我瞭解 - 這個想法基本上是創建一個SOAP XML包,併發送它,並等待一個XML響應。有一個在.NET上運行的測試客戶端可以正常工作,所以我讓那個在Fiddler上寫這個動作的人知道,所以我可以看到xml和請求頭應該是什麼樣子。現在礦等同於他的,但我可以從服務器鼓起唯一的反應是:

<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://www.tempuri.org/IFoolSpoon_SoWo_Service/Check_Item_test' 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> 

由於是滾動遙遠的屏幕 - 這是一個錯誤ContractMismatch - 不管這實際上意味着。 面臨的挑戰:在谷歌搜索上述錯誤信息 - 任何人都不可能解釋術語「合同」而不使用「合同」一詞。 ;)我看到的每一個解釋基本上都是「它就像......合同 - 你知道......就像客戶端和服務器之間的合同......就像合同一樣。」 :(

總之,這裏是有關OBJ-C代碼,其名稱/網址更改爲保護有罪:關於上述代碼

// construct a URL that will ask the service for what we want 
NSURL *url = [NSURL URLWithString:@"http://mymachine.myisp.com/SOWO/MyService.svc"]; 

// build the SOAP envelope 
NSString *soapMessage = [NSString stringWithFormat: 
         @"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" 
         "<s:Body >\n" 
         "<Check_Item_test xmlns=\"http://derp.org/\">\n" 
         "<UPC>1090000021</UPC>\n" 
         "</Check_Item_test>\n" 
         "</s:Body>\n" 
         "</s:Envelope>\n"]; 

soapMessage = [soapMessage stringByReplacingOccurrencesOfString:@"\n" withString:@"\r\n"]; 

// put URL into a NSURLRequest 
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 
NSLog(@"length = %@", msgLength); 
[req addValue: @"text/xml" forHTTPHeaderField:@"Content-type"]; 
[req addValue: @"http://www.tempuri.org/IServiceInterface/Check_Item_test" 
     forHTTPHeaderField:@"SOAPAction"]; 
[req addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[req addValue:@"100-continue" forHTTPHeaderField:@"Expect"]; 
[req setHTTPMethod:@"POST"]; 
[req setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

的一些注意事項還有另外一個開發商從調用同一服務Ruby和他提到了一些事情:從\ n將行結束符改爲\ n是他的建議,因爲他發現這對他是一個問題,我還調整了一些標題大寫:SOAPaction到SOAPAction等。現在我完全匹配他的xml /頭文件,但沒有運氣。

我的請求看起來像這樣(來自OSX Fiddler等價物):

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Body > 
<Check_Item_test xmlns="http://derp.org/"> 
<UPC>1090000021</UPC> 
</Check_Item_test> 
</s:Body> 
</s:Envelope> 

這似乎符合所有其他客戶端,他們都工作保存我的。所以是的 - 幫助?我離服務的web.config只有一度的距離,並且我可以訪問服務器上的.svclog。有趣的是 - 我的請求沒有得到記錄,即使是logMalformedRequests設置爲true。建議在哪裏可以檢查我的請求進入的任何bitbucket,都會受到讚賞。

所以耶 - 生氣,沮喪,累了。對於那些應該如此簡單的事情來說,這已經變成了巨大的痛苦。這可能是愚蠢的,所以也許我只需要比我自己更多的目光。

TIA。

+0

爲節後人羣提供一個平臺。 – MonkRocker

回答

0

所以答案竟然是:停止使用SOAP。

我最終將服務端點重寫爲REST端點,並且一切都很好。