C# WCF和使用WEBGET在浏览器中测试服务

C# WCF和使用WEBGET在浏览器中测试服务,c#,vb.net,web-services,wcf,webget,C#,Vb.net,Web Services,Wcf,Webget,嗨,我是使用WCF(半天以前)的一个新用户,我已经创建了一个服务,我可以通过localhost看到它 ?-不是404 然而,在我想通过应用程序连接到这个服务之前,我想看看这个服务是否真的返回了它的目的。(只是确保数据库连接正常等) 我的iSeries设备上有这个(不幸的是它在VB.Net中,但我知道C#…) 函数getData(ByVal参数为整数)为字符串 这当然会激发(或应该激发)service1.svc类中的getData方法 所以启动网络服务,我试着这样做 及 但是什么都没有。(

嗨,我是使用WCF(半天以前)的一个新用户,我已经创建了一个服务,我可以通过localhost看到它

?-不是404

然而,在我想通过应用程序连接到这个服务之前,我想看看这个服务是否真的返回了它的目的。(只是确保数据库连接正常等)

我的iSeries设备上有这个(不幸的是它在VB.Net中,但我知道C#…)


函数getData(ByVal参数为整数)为字符串
这当然会激发(或应该激发)service1.svc类中的getData方法

所以启动网络服务,我试着这样做

但是什么都没有。(也不调试代码)

环顾四周,这可能与我的web配置文件有关,我还没有碰过它

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false 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="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"/>
  </system.webServer>

</configuration>

我错过了什么


谢谢

您可以尝试设置明确的服务定义:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false 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="false"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="WebBehavior">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <services>
            <service name="WebApplication1.Service1">
                <endpoint address="" binding="webHttpBinding" contract="WebApplication1.IService" behaviorConfiguration="WebBehavior" />
            </service>
        </services>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <directoryBrowse enabled="true"/>
    </system.webServer>    
</configuration>

现在导航到
/Service1.svc/method/123
将调用正确的方法。

谢谢,非常有效,快速提问因为我不想发布新问题,我提供此服务是为了表明某些功能可以工作,但Web服务实际上将由第三方开发,它将是一个SOAP Web服务,因此基本上要使其成为SOAP,我将端点绑定从webHttpBinding更改为basicHttpBinding,这现在是否使其成为SOAP服务?是的,从
webHttpBinding
更改为
basicHttpBinding
使其成为
SOAP
服务。
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false 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="false"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="WebBehavior">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <services>
            <service name="WebApplication1.Service1">
                <endpoint address="" binding="webHttpBinding" contract="WebApplication1.IService" behaviorConfiguration="WebBehavior" />
            </service>
        </services>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <directoryBrowse enabled="true"/>
    </system.webServer>    
</configuration>
Imports System.ServiceModel
Imports System.ServiceModel.Web

<ServiceContract()>
Public Interface IService
    <OperationContract>
    <WebGet(UriTemplate:="/method/{parameter}")>
    Function getData(ByVal parameter As String) As String
End Interface
Public Class Service1
    Implements IService

    Public Function getData(ByVal parameter As String) As String Implements IService.getData
        Return "Foo bar"
    End Function
End Class