调用wcf服务端点未找到 [英] calling wcf service Endpoint not found

查看:83
本文介绍了调用wcf服务端点未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IIS中托管了一个wcf服务..我直接从IIS浏览服务。

我创建了服务,但是当我从浏览器浏览[链接]时(http:/ /localhost:55493/Service1.svc/MyFunction/apple)!我找不到端点了。



接口

 [OperationContract] 
[WebInvoke(方法= <跨度类= 代码串> <跨度类= 代码串 > *,BodyStyle = WebMessageBodyStyle.Wrapped,ResponseFormat = WebMessageFormat ())
string MyFunction( string Count);
// TODO:在此处添加服务操作
}



Class

 [AspNetCompatibilityRequirements(RequirementsMode 
= AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1:IService1
{
public string MyFunction( string Count)
{
return 您传递的名称是: + Count.ToString();
}
}



web.config

 <   system.serviceModel  >  
< 服务 >
< service name = WcfService3codepro.Service1 < span class =code-attribute> behaviorConfiguration = MyServiceBehaviour >
< 端点 地址 = binding = webHttpBinding 合同 = WcfService3codepro.IService1 behaviorConfiguration = MyEndpointBehavior / >
< / service >
< / services &g t;
< bindings >

< / bindings >
< 行为 >
< serviceBehaviors < span class =code-keyword>>
< 行为 名称 = MyServiceBehaviour >
<! - 避免披露m etadata信息,在部署之前将以下值设置为false - >
< serviceMetadata httpGetEnabled = true / >
<! - 要接收故障中的异常详细信息以进行调试,请将以下值设置为true。在部署之前设置为false以避免泄露异常信息 - >
< serviceDebug includeExceptionDetailInFaults = false / >
< / behavior >
< < span class =code-leadattribute> / serviceBehaviors >

< ; endpointBehaviors >
< 行为 名称 = MyEndpointBehavior >
< webHttp / >
< / behavior >
< / endpointBehaviors >
< / behavior >
< serviceHostingEnvironment multipleSiteBindingsEnabled = true / >
< / system.serviceModel >
< system.webServer < span class =code-keyword>>

< modules runAllManagedModulesForAllRequests = true / >
< ! -
要在调试期间浏览Web应用程序根目录,请将以下值设置为true。
在部署之前设置为false以避免泄露Web应用程序文件夹信息。
- >

< directoryBrowse 已启用 = true / >
< defaultDocument >
< 文件 >
< add value = Service1.svc / >
< / files >
< / defaultDocument >
< / system.webServer >

< / configuration >

解决方案
此问题是创建由于[WebInvoke(方法= *,BodyStyle = WebMessageBodyStyle.Wrapped,ResponseFormat <无线电通信/>


您正在使用ResponseFormat for WebInvoke

因此需要更改以下格式



 [ OperationContract] 
[WebGet(ResponseFormat = WebMessageFormat.Json)]
[FaultContract(typeof(KenException))]
List < 数据 > GetAllData(); //选择时间

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json)]
[FaultContract(typeof(KenException))]
DataInsertData(数据用户) ); //插入时间





谢谢


接口文件中的更改(IService1.cs)下面线,并再次测试:

 [WebInvoke(方法= GET,ResponseFormat = WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate =MyFunction的/ {值}))





希望它会对你有帮助!


I have hosted a wcf service in IIS ..and I browse service from IIS directly.
I got service is created, but when I browse from browser with [a link](http://localhost:55493/Service1.svc/MyFunction/apple)! I am getting Endpoint not found.

Interface

[OperationContract]
[WebInvoke(Method = "*", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
string MyFunction(string Count);
    // TODO: Add your service operations here
}


Class

[AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
    public string MyFunction(string Count)
    {
        return "The Name you passed  is: " + Count.ToString();
    }
}


web.config

<system.serviceModel>
      <services>
      <service name="WcfService3codepro.Service1" behaviorConfiguration="MyServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="WcfService3codepro.IService1" behaviorConfiguration="MyEndpointBehavior" />
      </service>
    </services>
    <bindings>

    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehaviour">
          <!-- 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="MyEndpointBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </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" />
        <defaultDocument>
            <files>
                <add value="Service1.svc" />
            </files>
        </defaultDocument>
  </system.webServer>

</configuration>

解决方案

This problem is created due to [WebInvoke(Method = "*", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat

It is happening you are using ResponseFormat for WebInvoke
So it needs to change below format

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
[FaultContract(typeof(KenException))]
List<Data> GetAllData();  //Select time

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json)]
[FaultContract(typeof(KenException))]
DataInsertData(Data user);//Insert Time



Thanks


Change in Interface file (IService1.cs) with below line and test it again:

[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "MyFunction/{value}")]



Hope it will help you!


这篇关于调用wcf服务端点未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆