doushu9253 2012-10-19 17:54
浏览 71
已采纳

在VB.Net中使用PHP Web服务

Here is the code I received from a customer on how they access their web service from PHP. I will need to do the same but from VB.Net. There is no WSDL available and this is all the code I have from them. Is this even possible?

$Client = new SoapClient(NULL, array('location' => 'http://ipaddress/onyx/api/soap_api.php', 'uri' => 'not-used'));

print_r($Client->qty_available('124044'));

/* Output: Array ( [01] => Array ( [available] => 333 [name] => Alliance )

  • 写回答

2条回答 默认 最新

  • douyu0845 2012-10-19 18:20
    关注

    If the data being returned is in a custom format (I'm guessing this from the question) then the default web service stuff might not work in .Net, you'll have to manually get the data from the request and parse it based on what the service returns. If it is in a standard XML, you may have to get the raw data once just to create the WSDL yourself.

    Here is some code from a console app we used to test one of our .Net web services. Basically its making the request and returning the raw data. You could run this once to get the data that is returned, and then write the code to parse the data. I replaced our values with the ones from your question.

    Module Module1
    
    Sub Main()
    
    
        Dim x = System.Net.HttpWebRequest.Create("http://ipaddress/onyx/api/soap_api.php")
    
        x.Method = "POST"
    
        Dim MemStream As New System.IO.MemoryStream
    
        Dim ReqData As New IO.StreamWriter(MemStream, System.Text.Encoding.UTF8)
        ReqData.Write(My.Resources.Test2)
        ReqData.Flush()
    
        x.ContentLength = MemStream.Length
        x.ContentType = "text/xml; charset=utf-8"
        x.Headers.Add("SOAPAction", "not-used")
    
        Dim WebReq = x.GetRequestStream
        WebReq.Write(MemStream.GetBuffer, 0, MemStream.Length)
        WebReq.Flush()
        WebReq.Close()
    
        Dim Res As System.Net.HttpWebResponse = x.GetResponse
    
        If Res.StatusCode = Net.HttpStatusCode.OK Then
            Dim SR = New IO.StreamReader(Res.GetResponseStream)
            Console.WriteLine(SR.ReadToEnd)
        Else
            Console.WriteLine(Res.StatusCode & ", " & Res.StatusDescription)
        End If
    
        Console.ReadLine()
    
    End Sub
    
    End Module
    

    The `My.Resources.Test2' is the pre-formatted request data we were using. Here is a possible example for your situation, it may not be correct.

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <qty_available>
             124044
        </qty_available>
    </soap:Body>
    </soap:Envelope>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)