运行应用程序时,WCF方法名称未显示

时间:2017-08-02 10:39:13

标签: c# xml web-services wcf

我正在开发WCF Web服务。我创建了一个服务,当我运行该服务时,我没有看到列出的任何方法。

我附上了截图:

Missing method name

这是我创建的服务和方法:

XML请求

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
 <SOAP-ENV:Body>
 <opportunityID>1-1DA7KN</opportunityID>
 <opportunityStatus>Created</opportunityStatus>
 <opportunityserviceType>LEASE_REQUEST</opportunityserviceType>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
[ServiceContract]
public interface IOpportunity
{
    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, 
     UriTemplate = "postmethod/updateOpportunity")]
    bool updateOpportunity(opportunityActivity obj);
}

[DataContract]
public class opportunityActivity
{
    [DataMember]
    public string opportunityID { get; set; }
    [DataMember]
    public string opportunityStatus { get; set; }
    [DataMember]
    public string opportunityserviceType { get; set; }
}

这是我的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="RayaSoapService.Opportunity">
        <endpoint address="" contract="RayaSoapService.IOpportunity" binding="basicHttpBinding"/>
        <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <!--
        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" />
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <connectionStrings>
    <add name="Test_ROLSP_DB_V1Entities" connectionString="metadata=res://*/Model.ModelModel.csdl|res://*/Model.ModelModel.ssdl|res://*/Model.ModelModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.0.210;initial catalog=Test_ROLSP_DB_V1;user id=sa;password=123@root;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

以上代码工作正常。我用web客户端测试了它。现在我想将它暴露给某些第三方,所以我应该给它们xml格式。我无法弄清楚如何获得上述服务的xml格式?每当我运行服务时,我都无法看到页面上列出的方法。有人可以帮助我获取上述请求的xml吗?任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

您需要添加MEX端点行为配置,我想您已经错过了它。

    <services>
      <service name="RayaSoapService.Opportunity" 
 behaviorConfiguration="mexBehaviour">
        <endpoint address="" contract="RayaSoapService.IOpportunity" binding="basicHttpBinding"/>
        <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <!-- To avoid disclosing metadata information, set the values 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>