ios Objective-C 连接到 asmx Web 服务的奇怪行为(IIS 上的 C#)

标签 ios objective-c iis asmx

我有一个简单的 asmx Web 服务。它曾在我们旧的 winphone 应用程序中使用,现在我想在新应用程序中使用它。 Android 上的 xamarin.forms 应用程序运行良好。来自本地网页的测试效果很好。但对于 ios/objective C 应用程序,我完全错过了。

我安装了本地iis(在w10笔记本上),服务在浏览器中运行良好,可以调试等。

在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 连接到它时。它失败并出现异常(如下)

我安装了 fiddler 作为反向代理。我的应用程序通过 fiddler 运行良好,但如果我直接连接,则会从服务器获得异常

我只更改一行代码

#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

最佳答案

嗯, 我解决了这个问题并找到了所有问题的答案,除了 - 为什么 xamarin.forms 在 android 版本上工作。 ;)

问题与解答: 1)应用程序通过fiddler工作而不是直接工作。 Telerik 网站上有一篇文章介绍了 fiddler 可以解决某些应用程序的网络问题的情况 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 上运行以及为什么它可以通过 fiddler 运行

关于ios Objective-C 连接到 asmx Web 服务的奇怪行为(IIS 上的 C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56902695/

相关文章:

asp.net-mvc - 强制 SSL 证书更新?

ios - 添加为背景图像的 subview 后按钮不起作用

ios - 停止来自另一个 View Controller 的音乐

ios - 使用 Core Data 进行排序的 fetchRequest 有哪些限制?

objective-c - 尝试通过核心数据保存文档窗口尺寸

ios - 如何在方法调用后重定向谷歌页面

asp.net - 防止将父 web.config 继承到 IIS 7.5 上的子应用程序

php - IIS 中 PHP 和 ASP 的提示

ios - 如何使用 swift 从解析类中查询/检索随机对象?

iphone - IAP 完成时隐藏/取消隐藏 IBOutlet(UIButton)