我必须在 Windows Phone 8 应用程序上使用网络服务 (WSDL),但它在 VS2012 中不起作用。
例如:
http://chennaiemergency.co.in/sree/s2.php?wsdl
- 右键单击项目 > 添加服务引用
- 将 URL 粘贴到地址文本框中
- 点击“开始”按钮
- 服务随所有操作一起出现
- 点击“确定”
添加了服务,但是在reference.cs中没有关于我操作的任何内容...
还有其他方法可以使用我的 wsdl 吗?
最佳答案
我找到的解决此问题的最佳方法是手动发送 SOAP 请求。 SOAP 和 wsdl 与 WP 的兼容性不是很好。如果可以选择,可以为您的 Web 服务选择 WCF。 我在 Windows 窗体应用程序中的 soap 请求代码(在 WP 项目中,您必须使用异步方法 -> beginGetRequestStream() & beginGetResponse() 。msdn 上有很多关于此的文档):
// Building of my XML
XNamespace env = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace xsd = "http://www.w3.org/2001/XMLSchema";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace enc = "http://schemas.xmlsoap.org/soap/encoding/";
XNamespace typens = "urn:...";
XNamespace xsiType = "xsd:string";
XElement soapEnv = new XElement(env + "Envelope",
new XAttribute(XNamespace.Xmlns + "SOAP-ENV",env.NamespaceName),
new XAttribute(XNamespace.Xmlns + "xsd", xsd.NamespaceName),
new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName),
new XElement(env + "Body",
new XAttribute(env + "encodingStyle",enc.NamespaceName),
new XElement(typens + "MethodName",
new XAttribute(XNamespace.Xmlns + "typens",typens.NamespaceName),
new XElement("elementName",
new XAttribute(xsi + "type",xsiType.NamespaceName), "...value"),
new XElement("elementName",
new XAttribute(xsi + "type",xsiType.NamespaceName),"...value"),
new XElement("elementName",
new XAttribute(xsi + "type",xsiType.NamespaceName),"...value")
)));
// HTTPWEBREQUEST
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("...url...");
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webRequest.Method = "POST";
webRequest.KeepAlive = false;
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.CookieContainer = new CookieContainer();
webRequest.Headers.Add("SOAPAction", "...webservice link...");
webRequest.ProtocolVersion = new Version(1,1);
webRequest.Timeout = 1000;
using (StreamWriter stream = new StreamWriter(webRequest.GetRequestStream()))
{
stream.Write(soapEnv);
stream.Flush();
stream.Close();
}
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()))
{
if (responseReader != null)
{
.....code....
webResponse.Close();
}
}
}
关于c# - WSDL 与 Windows Phone 8 兼容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14634902/