(vb.net) 发送一个 SOAP 信封

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23963347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:38:17  来源:igfitidea点击:

(vb.net) send a SOAP envelope

vb.netweb-servicessoap

提问by romulus001

I consume a web service (available there) and I need to generate and to send a SOAP envelope, but it's not something i do understand. I've found this example: http://macunsw.wordpress.com/2010/11/19/vb-net-example-for-calling-web-service-by-posting-soap-xml/but still, i do not get it, the envelope i need to send is like that:

我使用了一个网络服务(在那里可用),我需要生成并发送一个 SOAP 信封,但这不是我理解的东西。我找到了这个例子:http: //macunsw.wordpress.com/2010/11/19/vb-net-example-for-calling-web-service-by-posting-soap-xml/但我仍然这样做没收到,我要寄的信封是这样的:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.sunat.gob.pe" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
<soapenv:Header> 
<wsse:Security> 
<wsse:UsernameToken>
<wsse:Username>20100066603MODDATOS</wsse:Username> 
<wsse:Password>moddatos</wsse:Password> 
</wsse:UsernameToken> 
</wsse:Security> 
</soapenv:Header> 
<soapenv:Body> 
<ser:sendBill> 
<fileName>20100066603-01-F001-1.zip</fileName> 
<contentFile>cid:20100066603-01-F001-1.zip</contentFile> 
</ser:sendBill> 
</soapenv:Body> 
</soapenv:Envelope>

Can someone help? thx

有人可以帮忙吗?谢谢

回答by Kevin Sandow

Since you're using VB.Net you're not required to handle the SOAP services on your own.

由于您使用的是 VB.Net,因此您不需要自己处理 SOAP 服务。

Add the WSDL path http://...?wsdlas a remote Service:

将 WSDL 路径添加http://...?wsdl为远程服务:

  • in the Solution Explorer rightclick your project
  • Choose Add Service Referencefrom the context menu
  • enter the path to WSDL in the Address field & Click Go
  • the billService should be found
  • choose a namespace, i.e. Sunat
  • 在解决方案资源管理器中右键单击您的项目
  • 选择Add Service Reference从上下文菜单
  • 在“地址”字段中输入 WSDL 的路径并单击“前往”
  • 应该找到 billService
  • 选择一个命名空间,即 Sunat

From now on you can access the service as a simple object:

从现在开始,您可以将服务作为一个简单的对象访问:

Dim billService As New Sunat.billServiceClient
billService.sendBill(fileName, contentFile)
billService.sendSummary(fileName, contentFile)
billService.getStatus(ticket)