0

我的服务器在应用服务器上托管我的 WSDL。在我自己的 IP 地址本地运行时,我能够访问该服务并使用这些方法。但是在我们的应用服务器上运行时,我只能访问 WSDL,引用它并查看它具有的方法,但不能使用这些方法。我在 VB.NET 4.0 中将它作为控制台应用程序运行。我得到一个 InternalServiceFault。

Public Class pokeWCF
   Implements poke

   Dim objFile As String = "C:\Users\lsj\Documents\Visual Studio 2012\Projects\ConsoleServer\easyA.txt"
   Dim aryText() As String
   Dim sK As String
   Dim fM As String
   Dim msg As String
   Dim time As DateTime = DateTime.Now
   Dim format As String = "ddd d HH:mm yyyy"
   Dim OracleReceive As New ReceiveOrcl

   Public Function backTo(securityKey As String, from As String, message As String) As ServiceResult Implements poke.backTo
   'stuff
   End Function

   Public Function Test(securityKey As String) As ServiceResult Implements poke.Test
   'moreStuff
   End Function
End Class

Sub Main()
    Dim strHostName As String
    Dim strIPAddress As String
    strHostName = System.Net.Dns.GetHostName()

    strIPAddress = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()
    MsgBox(strIPAddress.ToString)

    Dim url As Uri = New Uri("http://" & strIPAddress & ":22380/poke")
    Dim host As New ServiceHost(GetType(pokeWCF), url)
    Dim smb As New ServiceMetadataBehavior()
    Console.WriteLine("CRAB BATTLE!")
    Console.Write("Server Up" & vbCrLf)

    smb.HttpGetEnabled = True
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
    host.Description.Behaviors.Add(smb)
    host.Open()

    Console.WriteLine("Running at " & url.ToString)
    Console.Read()

End Sub

在查看了从应用服务器生成的 WSDL 之后,我的 localhost 的定义有所不同。

编辑:

本地生成的 WSDL:

 <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="RacoSMSWCF" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import namespace="https://t-mobile.racowireless.com/SMSRicochet1.0"/>
<xs:element name="ReceiveSMS">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="securityKey" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="from" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ReceiveSMSResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="https://t-mobile.racowireless.com/SMSRicochet1.0" minOccurs="0" name="ReceiveSMSResult" type="q1:ServiceResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="securityKey" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="TestResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q2="https://t-mobile.racowireless.com/SMSRicochet1.0" minOccurs="0" name="TestResult" type="q2:ServiceResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns:char"/>
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration"/>
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid"/>
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="https://t-mobile.racowireless.com/SMSRicochet1.0" elementFormDefault="qualified" targetNamespace="https://t-mobile.racowireless.com/SMSRicochet1.0">
<xs:simpleType name="ServiceResult">
<xs:restriction base="xs:string">
<xs:enumeration value="ACCEPTED"/>
<xs:enumeration value="MESSAGE_TOO_LONG"/>
<xs:enumeration value="INVALID_CREDENTIALS"/>
<xs:enumeration value="REJECTED"/>
<xs:enumeration value="NOTFOUND"/>
<xs:enumeration value="INVALID_RECIPIENT"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="ServiceResult" nillable="true" type="tns:ServiceResult"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="racoSMS_ReceiveSMS_InputMessage">
<wsdl:part name="parameters" element="tns:ReceiveSMS"/>
</wsdl:message>
<wsdl:message name="racoSMS_ReceiveSMS_OutputMessage">
<wsdl:part name="parameters" element="tns:ReceiveSMSResponse"/>
</wsdl:message>
<wsdl:message name="racoSMS_Test_InputMessage">
<wsdl:part name="parameters" element="tns:Test"/>
</wsdl:message>
<wsdl:message name="racoSMS_Test_OutputMessage">
<wsdl:part name="parameters" element="tns:TestResponse"/>
</wsdl:message>
<wsdl:portType name="racoSMS">
<wsdl:operation name="ReceiveSMS">
<wsdl:input wsam:Action="http://tempuri.org/racoSMS/ReceiveSMS" message="tns:racoSMS_ReceiveSMS_InputMessage"/>
<wsdl:output wsam:Action="http://tempuri.org/racoSMS/ReceiveSMSResponse" message="tns:racoSMS_ReceiveSMS_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Test">
<wsdl:input wsam:Action="http://tempuri.org/racoSMS/Test" message="tns:racoSMS_Test_InputMessage"/>
<wsdl:output wsam:Action="http://tempuri.org/racoSMS/TestResponse" message="tns:racoSMS_Test_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_racoSMS" type="tns:racoSMS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ReceiveSMS">
<soap:operation soapAction="http://tempuri.org/racoSMS/ReceiveSMS" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Test">
<soap:operation soapAction="http://tempuri.org/racoSMS/Test" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RacoSMSWCF">
<wsdl:port name="BasicHttpBinding_racoSMS" binding="tns:BasicHttpBinding_racoSMS">
<soap:address location="http://192.168.100.88:22380/racoSMS"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

应用服务器 WSDL:

     <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" name="RacoSMSWCF" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import namespace="https://t-mobile.racowireless.com/SMSRicochet1.0"/>
<xs:element name="ReceiveSMS">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="securityKey" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="from" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ReceiveSMSResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="https://t-mobile.racowireless.com/SMSRicochet1.0" minOccurs="0" name="ReceiveSMSResult" type="q1:ServiceResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="securityKey" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="TestResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q2="https://t-mobile.racowireless.com/SMSRicochet1.0" minOccurs="0" name="TestResult" type="q2:ServiceResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns:char"/>
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration"/>
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid"/>
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="https://t-mobile.racowireless.com/SMSRicochet1.0" elementFormDefault="qualified" targetNamespace="https://t-mobile.racowireless.com/SMSRicochet1.0">
<xs:simpleType name="ServiceResult">
<xs:restriction base="xs:string">
<xs:enumeration value="ACCEPTED"/>
<xs:enumeration value="MESSAGE_TOO_LONG"/>
<xs:enumeration value="INVALID_CREDENTIALS"/>
<xs:enumeration value="REJECTED"/>
<xs:enumeration value="NOTFOUND"/>
<xs:enumeration value="INVALID_RECIPIENT"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="ServiceResult" nillable="true" type="tns:ServiceResult"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="racoSMS_ReceiveSMS_InputMessage">
<wsdl:part name="parameters" element="tns:ReceiveSMS"/>
</wsdl:message>
<wsdl:message name="racoSMS_ReceiveSMS_OutputMessage">
<wsdl:part name="parameters" element="tns:ReceiveSMSResponse"/>
</wsdl:message>
<wsdl:message name="racoSMS_Test_InputMessage">
<wsdl:part name="parameters" element="tns:Test"/>
</wsdl:message>
<wsdl:message name="racoSMS_Test_OutputMessage">
<wsdl:part name="parameters" element="tns:TestResponse"/>
</wsdl:message>
<wsdl:portType name="racoSMS">
<wsdl:operation name="ReceiveSMS">
<wsdl:input wsam:Action="http://tempuri.org/racoSMS/ReceiveSMS" message="tns:racoSMS_ReceiveSMS_InputMessage"/>
<wsdl:output wsam:Action="http://tempuri.org/racoSMS/ReceiveSMSResponse" message="tns:racoSMS_ReceiveSMS_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Test">
<wsdl:input wsam:Action="http://tempuri.org/racoSMS/Test" message="tns:racoSMS_Test_InputMessage"/>
<wsdl:output wsam:Action="http://tempuri.org/racoSMS/TestResponse" message="tns:racoSMS_Test_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_racoSMS" type="tns:racoSMS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ReceiveSMS">
<soap:operation soapAction="http://tempuri.org/racoSMS/ReceiveSMS" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Test">
<soap:operation soapAction="http://tempuri.org/racoSMS/Test" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RacoSMSWCF">
<wsdl:port name="BasicHttpBinding_racoSMS" binding="tns:BasicHttpBinding_racoSMS">
<soap:address location="http://192.168.200.27:22380/racoSMS"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

编辑:

从我发现 WCF 测试客户端后,我在测试服务器上运行的服务后收到此错误。

 The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at racoSMS.Test(String securityKey)
   at racoSMSClient.Test(String securityKey)
4

1 回答 1

1

您已经创建了 ServiceHost 并使用 HttpGetEnabled 设置了 ServiceMetadataBehavior,以便可以在地址 http://?wsdl 访问服务 WSDL。看起来唯一缺少的是需要添加到 ServiceHost 的端点。

您可以使用以下语法添加端点:

host.AddServiceEndpoint(GetType([ServiceContractType]), [binding], "[url]");

ServiceContract 类型应该由您的服务类实现(它通常是一个接口,在这种情况下看起来像是“poke”)。

有许多可用的绑定(更多信息在这里),你使用什么将取决于你想要支持什么样的客户端以及你想要提供什么样的功能(安全性、可靠性、事务等)。BasicHttpBinding 是最向后兼容的,可以与任何符合 WS-I Basic Profile 规范的东西一起使用。

您在端点中提供的 url 将附加到您在创建该对象时提供给 ServiceHost 的基本 url。

于 2012-08-20T15:18:26.470 回答