如何转换ASMX Web引用方法HttpWebRequest
本文关键字:Web 引用 方法 HttpWebRequest ASMX 何转换 转换 | 更新日期: 2023-09-27 18:13:21
最近我开始创建一个Xamarin-iOS应用程序,它使用ProjectServer PSI WebService。当我将PSI添加为WebReference并尝试访问PSI方法时,我得到401未经授权的错误。有趣的是,它在本地网络中工作良好,但在企业网络中出现错误。所以我打算把webrereference改成SOAP - HttpwebRequest方法。
This is what i Tried
我试图获得资源id使用此url BaseAddress + pwa/_vti_bin/PSI/resource .asmx?op = GetCurrentUserUid
<?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>
<GetCurrentUserUid xmlns="http://schemas.microsoft.com/office/project/server/webservices/Resource/" />
</soap:Body>
我把上面的代码作为body传递。
但是当我使用HttpWebRequest执行此操作时,我得到错误HttpStatusCode InternalServerError System.Net.HttpStatusCode
同样在响应中,我发现了以下xml响应。
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
xmlns:a="http://Microsoft.Office.Project.Server">a:ProjectServerFaultCode
</faultcode>
<faultstring>
Unhandled Communication Fault occurred
</faultstring>
<detail>
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
Object reference not set to an instance of an object.</string></detail>
</s:Fault>
</s:Body>
</s:Envelope>
我不知道怎么了。我的问题是,
是否可以使用HttpWebRequest调用PSI方法如果没有,有什么替代方案。
请帮助。
以下是一些项目:
- URL应该是:BaseAddress + pwa/_vti_bin/PSI/Resource.asmx
- SOAP动作报头:ReadResource
-
在您的示例中,soap:body应该是…
<SOAP:BODY> <ReadResource> <resourceUid>value</resourceUid> </ReadResource> </SOAP:BODY>