0

WCF Restful Service を使用しようとしています。サービス構成は次のとおりです

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttp" maxReceivedMessageSize ="50000000" maxBufferPoolSize="50000000" >
      <readerQuotas maxDepth="500000000" maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000" maxStringContentLength="500000000"/>
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
    <services>
  <service behaviorConfiguration="ItemTracker.ItemTrackerServiceBehavior" name="ItemTracker.ItemTrackerService">
            <endpoint address="http://localhost:8003/ItemTracker/ItemTrackerService.svc" binding="wsHttpBinding" contract="ItemTracker.IItemTrackerService" bindingConfiguration="wsHttp">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ItemTracker.ItemTrackerServiceBehavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

インターフェイスは次のように定義されます

Imports System.ServiceModel.Web
<ServiceContract([Namespace]:="http://localhost:8003/ItemTracker/")> _    
Public Interface IItemTrackerService

<OperationContract()> _
<WebInvoke(Method:="POST", RequestFormat:=WebMessageFormat.Xml, ResponseFormat:=WebMessageFormat.Xml, UriTemplate:="GetItemTrackingDetails")> _
Function GetItemTrackingDetails(ByVal TrackingNo As String) As String

End Interface 

クライアント アプリケーションでの Restful サービスの呼び出しは次のとおりです。

Dim req As HttpWebRequest = Nothing
    Dim res As HttpWebResponse = Nothing

    Dim url As String = "http://localhost:8003/ItemTracker/ItemTrackerService.svc?wsdl/GetItemTrackingDetails/"
    req = DirectCast(WebRequest.Create(url), HttpWebRequest)
    req.Method = "POST"
    req.ContentType = "application/soap+xml; charset=utf-8"
    req.Timeout = 30000
    req.Headers.Add("SOAPAction", url)
    Dim xmlDoc As New System.Xml.XmlDocument()
    xmlDoc.XmlResolver = Nothing
    xmlDoc.Load(AppDomain.CurrentDomain.BaseDirectory & "\test.xml")
    Dim sXML As String = xmlDoc.InnerXml
    req.ContentLength = sXML.Length
    Dim sw As New System.IO.StreamWriter(req.GetRequestStream())
    sw.Write(sXML)
    sw.Close()
    res = DirectCast(req.GetResponse(), HttpWebResponse)

入力xmlはこれです。

<GetItemTrackingDetails xmlns="http://localhost:8003/ItemTracker/"> 
<TrackingNo>A10001</TrackingNo> 
</GetItemTrackingDetails>

localhost の代わりにシステム名が使用されます

GetItemTrackingDetails の出力は xml です。これにより、xml ではなく悪いリクエスト 400 が返されます

私を助けてくれる人はいますか。

4

2 に答える 2

0

実際のサービスへの URL を指定する必要はなく、URL マスクだけを指定します。

http://localhost:8003/ItemTracker/GetItemTrackingDetails/

さらに、プレースホルダーを URL マスクに追加して、操作への入力パラメーターを含める必要があります。

UriTemplate:="GetItemTrackingDetails/{0}"

これにより、実際の URL を呼び出して、URL の末尾に TrackingNo 変数を渡すことができます。

http://localhost:8003/ItemTracker/GetItemTrackingDetails/999AAA
于 2012-05-29T10:07:04.473 に答える