我有一个简单的asmx Web服务。它在我们旧的winphone应用程序中使用过,现在我想在新的应用程序中使用它。 android上的xamarin.forms应用程序运行良好。来自本地网页的测试效果很好。但是,使用ios /目标C应用程序我完全错过了。
我在w10笔记本电脑上安装了本地iis,服务在浏览器中运行良好,可以调试等。
在iis日志中,来自浏览器的请求与一个应用程序相似,但结果不同
'2019-07-05 09:00:35 fe80::54ae:f86a:269:32ce%14 POST /ws/bcws.asmx/GetCurrencyList - 80 - fe80::54ae:f86a:269:32ce%14 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64;+rv:67.0)+Gecko/20100101+Firefox/67.0 http://ish-xps/ws/bcws.asmx?op=GetCurrencyList 200 0 0 780'
'2019-07-05 09:06:17 192.168.101.159 POST /ws/bcws.asmx/GetCurrencyList - 80 - 192.168.101.137 bc2+IOS+request businesscalc 500 0 0 9'
当我从Mac(在同一wifi网络上)或ipad在同一网络上连接到它时。它因异常而失败(如下)
我安装了提琴手作为反向代理。我的应用程序通过提琴手运行良好,但是如果我直接连接,则会从服务器获取异常
我仅更改一行代码
#define SERVER_ADDR @"ish-xps"
到
#define SERVER_ADDR @"ish-xps:8888"
下面是请求代码
可能有人知道我在做什么错? 提前致谢
-(BOOL) GetCurrencyList
{
soapReq_GetCurrencyList = @" \
<?xml version=\"1.0\" encoding=\"utf-8\"?> \
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
<soap:Body> \
<GetCurrencyList xmlns=\"http://ish-xps/ws\" /> \
</soap:Body> \
</soap:Envelope> \
\
";
[self sendToServerWithRequest:soapReq_GetCurrencyList];
return (true);
}
-(BOOL) sendToServerWithRequest:(NSString *)req
{
NSString *connectStr = [NSString stringWithFormat:@"http://%@/ws/bcws.asmx/GetCurrencyList", SERVER_ADDR];
NSURL *serverUrl = [NSURL URLWithString:connectStr];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:serverUrl];
NSString *reqLength = [NSString stringWithFormat:@"%lu", (unsigned long) req.length];
NSString *soapAction = [NSString stringWithFormat:@"http://%@/ws/GetCurrencyList",SERVER_ADDR];
[request addValue:@"bc2 IOS request" forHTTPHeaderField:@"User-Agent"];
[request addValue:SERVER_ADDR forHTTPHeaderField:@"HOST"];
[request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:reqLength forHTTPHeaderField:@"Content-Length"];
[request addValue:soapAction forHTTPHeaderField:@"SOAPAction"];
[request addValue:@"businesscalc" forHTTPHeaderField:@"Referer"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[req dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if (connect)
{
return (true);
}
else
{
return (false);
}
}
Server Error in '/ws' Application.
Request format is unrecognized for URL unexpectedly ending in '/GetCurrencyList'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetCurrencyList'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetCurrencyList'.]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +401372
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +281
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +89
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +564
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263
答案 0 :(得分:0)
好吧, 我解决了这个问题,并找到了所有问题的答案,除了-为什么在Android版本上运行xamarin.forms可行。 ;)
问题和答案: 1)应用程序通过提琴手工作,而不是直接工作。 Telerik网站上有一篇文章,介绍了提琴手可能会解决该应用程序的某些网络问题的某些情况 https://www.telerik.com/blogs/details/help!-running-fiddler-fixes-my-app-
2)服务器异常。用已知溶液固化 添加
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
到应用程序webconfig 详情在这里 https://web.archive.org/web/20100523032751/http://support.microsoft.com/kb/819267
但是我不明白为什么xamarin.forms版本可以在android上运行,以及为什么它可以通过提琴手运行