使用wsHttpBinding添加wcf服务时显示错误消息 [英] showing error message while add wcf service with wsHttpBinding

查看:65
本文介绍了使用wsHttpBinding添加wcf服务时显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的wcf包含通用列表,它有3个函数和3个返回类型1个通用列表,2个数据集,3个bool类型



没有任何绑定默认它正常工作..但是当我试图添加wsHttpBinding时它显示如下的错误信息...



无法添加服务。服务元数据可能不是确保您的服务正在运行并公开元数据。



我的要求是我对这些数据使用安全绑定(返回数据,如通用列表,数据集,布尔)在运输级别和消息级别..



ppl你可以帮我解决这个问题



我的总代码在这里



IService1.cs



my wcf contains generic list and its having 3 functions and 3 return types 1-generic list,2-dataset,3-bool type

without any binding by default its working properly.. but when am trying to add wsHttpBinding its showing error message like this...

"Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata."

my requirement is i wana use secure binding for this data(return data like generic list,dataset,bool) in transport level and message level..

ppl can u help me out from this problem

my total code here

IService1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace samplewcf
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        List<result> personaldata(string userid);
        //[OperationContract]
        //void add(result1 s);
        [OperationContract]
        DataSet gridbind();

        [OperationContract]
        bool fun();

        // TODO: Add your service operations here
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class result
    {
        [DataMember]
        public int Nofid
        {
            get;
            set;
        }
        [DataMember]
        public string Name
        {
            get;
            set;
        }
        [DataMember]
        public bool Gender
        {
            get;
            set;
        }
        [DataMember]
        public char Status
        {
            get;
            set;
        }
    }
    
   
}





Service.svc。 cs





Service.svc.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace samplewcf
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        List<result> res = new List<result>();
        public List<result> personaldata(string userid)
        {

           //am using some data source.. for this data but.. its ok with values 1,person,true,A

            result rs = new result();
            rs.Nofid = 1;
            rs.Name = "person";
            rs.Gender = true;
            rs.Status = 'A';
            res.Add(rs);
            //rls.Add(rs);
            return res;        

        }
        public DataSet gridbind()
        {          //here am using some data source..  u can user any data that store in dataset
            DataSet ds = new DataSet();
            return ds;          

        }
        public bool fun()
        {
            return true;
        }
    }
}





web.config文件





web.config file

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="samplewcf.Service1"
        behaviorConfiguration="samplewcf.Service1Behavior">

        <!-- Service Endpoints -->
        <endpoint address="ServiceFile.svc" binding="wsHttpBinding" contract="samplewcf.IService1">
        </endpoint>
        <endpoint address="Service1.svc" binding="wsHttpBinding"   contract="samplewcf.IService1"/>


        <endpoint address="mex" binding="mexHttspBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="True" 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>
    <bindings>
      <wsHttpBinding>
        <binding name="TransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>









so ppl在这里我的所有代码..只是检查它..我wana这个wcf服务在wsBttpBinding与安全绑定和ppl等待你的宝贵答案





so ppl here my all code.. just check it..i wana this wcf service in wsBttpBinding with secure binding and ppl am waiting for ur valuable answers

推荐答案

你需要提供服务标记内的端点地址。

您可以提供绝对或相对URL。



但是提供相对Url是最好的方法,因为当你在IIS中托管它时,绝对Url可能会改变,但是相对将是相同的,你不需要再改变它。 />


因此,如果web.config和服务.svc文件位于同一目录,那么直接广告d地址中的文件名如下所示。

You need to provide the endpoint address inside the service tag.
You can provide the absolute or relative Url.

But providing a relative Url is the best method, because when you host that in IIS, the absolute Url may change, but the relative will be the same and you don''t need to change that again.

So, if the web.config and the service .svc file are at the same directory, then directly add the filename in the address like below.
<endpoint address="ServiceFile.svc" binding="wsHttpBinding" contract="WcfService1.IService1">
</endpoint>



因此,您需要根据服务文件提供正确的相对地址。



让我知道它的工作与否。



[更新]



1. 包含服务行为

您已在web.config中添加了如下所示的服务。


So, you need to provide the correct relative address according of the Service file.

Let me know it works or not.

[Update]

1. Include Service Behaviour
You have added Service like below in web.config.

<service name="samplewcf.Service1"

        behaviorConfiguration="samplewcf.Service1Behavior">



但您必须忘记在 serviceBehaviors 标记内包含此行为。

如下所示(只需将此名称添加到现有行为中)...


But you have to forgot to include this behavior inside serviceBehaviors tags.
That is like below (Just add this name to the existing behavior)...

<serviceBehaviors>
        <behavior name="samplewcf.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="True" 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>





2. 端点绑定中的Typo错误



2. Typo mistake in endpoint binding

<service name="samplewcf.Service1"

        behaviorConfiguration="samplewcf.Service1Behavior">
 
        <!-- Service Endpoints -->
        <endpoint address="ServiceFile.svc" binding="wsHttpBinding" contract="samplewcf.IService1">
        </endpoint>
        <endpoint address="Service1.svc" binding="wsHttpBinding"   contract="samplewcf.IService1"/>
 
        <endpoint address="mex" binding="mexHttspBinding" contract="IMetadataExchange"/>
</service>



这应该是 mexHttpBinding 删除额外的s。

只保留所需的终​​点。



所以,这最终会如下所示。


This should be mexHttpBinding removing extra "s".
And keep only the required endpoint.

So, that will finally look like below.

<service name="samplewcf.Service1"

        behaviorConfiguration="samplewcf.Service1Behavior">
 
        <!-- Service Endpoints -->
        </endpoint>
        <endpoint address="Service1.svc" binding="wsHttpBinding"   contract="samplewcf.IService1"/> 

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>





请按照建议更正您的代码,它应该可以正常工作。我的工作正常。

如果你再次遇到问题,请告诉我。





注意 - 我刚刚解决了这个问题,我还没有检查服务功能的功能。你需要检查和测试。



谢谢......



Please correct your code as suggested, it should work fine. It is working fine at my end.
Let me know if you face issues again.


Note - I just resolved this issue, I have not checked the functionality of the Service functions. You need to check and test.

Thanks...


这篇关于使用wsHttpBinding添加wcf服务时显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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