无法在 web.config 中为 WCF Web 服务设置服务名称属性 [英] Cannot set service name attribute in web.config for WCF web service

查看:35
本文介绍了无法在 web.config 中为 WCF Web 服务设置服务名称属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我编写的 WCF Web 服务,它工作正常,然后我从另一个应用程序复制了该 Web 服务的内容并创建了一个新的 WCF 文件,该文件在 web.config 中创建了一个新文件,但名称属性表示命名空间不能是找到了.

I have a WCF web service I wrote which works fine, I then copied the contents of the web service from another application and created a new WCF file which created a new in web.config but the name attribute says the namespace cannot be found.

以下是我的 WCF 前几行的示例:

Here is an example of the first few lines of my WCF:

namespace Testing.ws.mainGrid
{
    [WebService(Namespace = "")]
    [ScriptService]
    [ToolboxItem(false)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Test : WebService
    {
        [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
        [WebMethod]
        public void GetRecords()
        {
            ((NameValueCollection)new WebClient().Headers).Add("accept", "text/xml");
            string str1 = "1";
            string str2 = "1";
            string str3 = "1";

这是我的 web.config:

Here is my web.config:

  <system.serviceModel>
        <services>
            <service name="Testing.ws.getStaffTree">
                <endpoint address="" behaviorConfiguration="Testing.ws.getStaffTreeAspNetAjaxBehavior"
                    binding="webHttpBinding" contract="Testing.ws.getStaffTree" />
            </service>
            <service name="Testing.ws.mainGrid.Test">
                <endpoint address="" behaviorConfiguration="Testing.ws.mainGridAspNetAjaxBehavior"
                    binding="webHttpBinding" contract="Testing.ws.mainGrid" />
            </service>
        </services>

基本上 name="Testing.ws.mainGrid.Test" 不起作用,也找不到.

Basically name="Testing.ws.mainGrid.Test" does not work and it cannot find it.

我不确定我做错了什么,但我已经花了很长时间!第一个工作正常,但第二个有问题.

I'm not sure what i'm doing wrong but i've spent ages on this! This first works fine but its the second one with the issue.

实际错误是:

'name' 属性无效 - 值 Testing.ws.mainGrid.Test 根据其数据类型 'serviceNameType' 无效 - 枚举约束失败

the 'name' attribute is invalid - The value Testing.ws.mainGrid.Test is invalid according to its datatype 'serviceNameType' - The enumeration constraint failed

如果您让智能感知完成它的工作,那么它会显示第一个 Web 服务,而不是我的新服务!

If you let intellisense do its work then it displays the first web service but not my new one!

推荐答案

我认为你的第二个服务应该如下.注意合约名称的变化:

Your second service should be as follows I think. Note the change in contract name:

<service name="Testing.ws.mainGrid.Test">
    <endpoint address="" behaviorConfiguration="Testing.ws.mainGridAspNetAjaxBehavior"
        binding="webHttpBinding" contract="Testing.ws.mainGrid.Test" />
</service>

在它指向命名空间之前,而不是类类型.

Before it was pointing to the namespace, not the class type.

这篇关于无法在 web.config 中为 WCF Web 服务设置服务名称属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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