我必须从C#程序中调用call服务。webservice很可能没有标准格式。接口描述(wsdl和xsd)非常复杂,使用代理生成机制会导致数百个类。生成的类没有什么帮助,因为它们是非常通用的,使用大多数简单的对象类型作为members.The的最佳选择是手动构建SOAP消息。这也是webservice提供者建议选择的方式:获取必须发送的soap/xml消息,并根据模板构建消息。现在的问题是如何最有效地构建消息。当然,对消息字符串进行硬编码也是一种选择,但是我想知道是否有更好的选择。如果我在一个字符串中有完整的消息,我如何最好地发送这些消息。我应该使用一个简单的HttpRequest,还是可以使用wcf栈的机制?我目前构建消息的方法如下所示:
string msg = envelopeBegin;
RouteType rootType = new RouteType();
XmlSerializer serializer = new XmlSerializer(typeof(RouteType));
StringWriter stringWriter = new StringWriter();
serializer.Serialize(stringWriter, rootType , customNamespace);
msg += stringWriter.ToString();
msg += envelopeEnd;//通过网络发送消息
我必须生成的Soap/xml消息如下所示
<env:Envelope>xmlns:env=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://www.skanska.se/oagis/9/ws/faults">
<env:Body>
<ska:ShowSalesOrder xmlns:ska="http://www.skanska.se/oagis/9" systemEnvironmentCode="UTV" versionID="1.0" releaseID="9.0">
<!--plsql=.74s-->
<ApplicationArea xmlns="http://www.openapplications.org/oagis/9">
<!--user_name=SEBA_RAPPE-->
<ska:Sender>
<LogicalID>OEBS_SE</LogicalID>
<ComponentID>SKAIS017I</ComponentID>
<AuthorizationID>SEBA_RAPPE</AuthorizationID>
<ska:ResponsibilityID>XXOM_INTEGRATION_SVT</ska:ResponsibilityID>
</ska:Sender>
<CreationDateTime>2010-02-26T15:03:27+01:00</CreationDateTime>
<BODID>xxxxxxxxxxxxxxxxx</BODID>
</ApplicationArea>
<ska:DataArea>
<Show xmlns="http://www.openapplications.org/oagis/9">
<ResponseCriteria>
<ResponseExpression actionCode="Never" expressionLanguage="xPath">*</ResponseExpression>
</ResponseCriteria>
</Show>
<ska:SalesOrder>
<SalesOrderHeader xmlns="http://www.openapplications.org/oagis/9">
<DocumentID>
<ID>141779</ID>
</DocumentID>
<RequestedShipDateTime>2009-11-04T07:00:54+01:00</RequestedShipDateTime>
</SalesOrderHeader>
</ska:SalesOrder>
</ska:DataArea>
</ska:ShowSalesOrder>
</env:Body>
</env:Envelope> 发布于 2010-02-28 07:01:40
您肯定仍然可以使用WCF基础设施,而不需要为所有不同的消息定义类型。WCF通过Message类明确支持这一点。使用它并不是那么困难。下面是关于它们的更多信息,但其思想基本上是使用XML读取器和写入器来读写消息。
Using the Message Class
发布于 2010-02-28 06:59:58
一种方法是创建一个包含值占位符的XML框架模板。读取XML并将这些值替换为对象中的值。使用HttpWebRequest将生成的XML发布到web服务。
即使这种方法可能行得通,我也强烈建议您创建一个WCF代理类并使用它,即使web服务包含数百个未使用的方法和对象。只要它是有效的WSDL,WCF就会处理它。此外,如果web服务有任何更改,您所要做的就是重新生成代理。为了避免这个web服务的丑陋,创建您自己的基础架构,它只公开有用的方法和类,并隐藏真正的调用。
https://stackoverflow.com/questions/2349231
复制相似问题