【发布时间】:2014-07-29 19:30:48
【问题描述】:
我正在尝试进行休息服务并对其进行测试。以下是生成的 wsdl 文件,但我无法使用 GetData 方法。
我来自 http://localhost:21611/Service1.svc?wsdl 的 WSDL 文件是一个有效的 url。
网络配置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/>
</diagnostics>
<bindings />
<services>
<service behaviorConfiguration="MyServiceBehavior" name="test.Service1">
<endpoint address="Service1.svc" behaviorConfiguration="myRestBehavior" binding="webHttpBinding" name="epname" contract="test.IService1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:21611" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="myRestBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" httpGetBindingConfiguration="" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
<handlers>
<remove name="svc-Integrated-4.0" />
<add name="svc-Integrated-4.0" path="*.svc" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
WCF 服务文件:
<ServiceContract()>
Public Interface IService1
<OperationContract()>
<WebGet>
Function GetData() As String
End Interface
Public Class Service1
Implements IService1
Public Function GetData() As String Implements IService1.GetData
Return "Welcome"
End Function
End Class
我尝试了类似的网址,但没有得到任何结果,请您指导我。
http://localhost:21611/Service1.svc?wsdl
http://localhost:21611/Service1.svc?wsdl/GetData
http://localhost:21611/Service1.svc?wsdl/GetData/
http://localhost:21611/Service1.svc/GetData
http://localhost:21611/Service1.svc/GetData/
另外,我在尝试时收到 404 错误:http://localhost:21611/Service1.svc/GetData
【问题讨论】:
-
REST 服务不使用 WSDL。您可能需要在
WebGet属性中指定 URI。 -
也厌倦了 UriTemplate:='GetData' 但仍然没有工作