soap request client to webservice using vb.net

夙愿已清 提交于 2019-12-11 06:48:56

问题


My question is similar to

How do I send/Receive SOAP messages usiung .NET

I wanted to invoke a webservice, however not like the way shown in the link above.What I did was, created a service reference with the wsdl url(in a windows application with a button click event)

http://ipaddress:port/My/MyService?wsdl

have created a client object

Dim objProxy As MyClient = New MyClient()

I have populated the objrequest and objreqheader using the below methods, (assigning string values and not xml)

objreqheader.id = "abcd"

Finally the below line invokes the service

objresponsehead = objProxy.myoperation(objreqheader, objrequest, objresp)

From reference vb, this is the myoperation public function

Public Function myoperation(ByVal RequestHeader As AFA.RequestHeaderType, ByVal GetTransactionDetailsReq As AFA.GetTransactionDetailsReqType, <System.Runtime.InteropServices.OutAttribute()> ByRef GetTransactionDetailsResp As AFA.GetTransactionDetailsRespType) As AFA.ResponseHeaderType
            Dim inValue As AFA.getTransactionDetailsRequest = New AFA.getTransactionDetailsRequest()
            inValue.RequestHeader = RequestHeader
            inValue.GetTransactionDetailsReq = GetTransactionDetailsReq
            Dim retVal As AFA.getTransactionDetailsResponse = CType(Me,AFA.myservice).getTransactionDetails(inValue)
            GetTransactionDetailsResp = retVal.GetTransactionDetailsResp
            Return retVal.ResponseHeader
        End Function

The problem is my objresp is coming as empty. There is no exception generated, objresponsehead is populated as "abcd". The service is not invoked. I am not sure how to get the trace file from the app config file, to debug the issue. I remember, when i used this for the first time, got an error "no endpoint listening that could accept the message", however there is no error now.

I added the below in the app config file to get the trace to see what is going on. But did not see any trace file(trace.log) generated.

<system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add type="System.Diagnostics.TextWriterTraceListener" name="TextWriter"              initializeData="trace.log" />
      </listeners>
    </trace>
  </system.diagnostics>

I checked the property of objProxy, it is having basic http binding as the property. Anyone invoked the service like this? From soapui, the response is fine, after i populate the request fields.

How can i enable the trace to see what is the request going and where is the problem.


回答1:


See Message Logging:

<system.diagnostics>
  <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
                 <add name="messages"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="c:\logs\messages.svclog" />
          </listeners>
      </source>
    </sources>
</system.diagnostics>

<system.serviceModel>
  <diagnostics>
    <messageLogging 
         logEntireMessage="true" 
         logMalformedMessages="false"
         logMessagesAtServiceLevel="true" 
         logMessagesAtTransportLevel="false"
         maxMessagesToLog="3000"
         maxSizeOfMessageToLog="2000"/>
  </diagnostics>
</system.serviceModel>


来源:https://stackoverflow.com/questions/8653187/soap-request-client-to-webservice-using-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!