简体   繁体   English

WCF Rest服务引用了另一个由WCF服务托管的应用程序。 找不到默认端点?

[英]WCF Rest service referencing another application hosted WCF Service. Could not find default endpoint?

My background is as follows: I have a WCF REST service which is the main service that consumers will communicate with. 我的背景如下:我有一个WCF REST服务,它是消费者要与之通信的主要服务。

I have a secondary application hosted WCF service (not REST based) which exposes a few methods. 我有一个托管WCF服务的辅助应用程序(不是基于REST的),它公开了一些方法。 This secondary one is necessary because I need the REST based service to be able to make calls into a 32-bit unmanaged library. 这个第二个是必须的,因为我需要基于REST的服务才能对32位非托管库进行调用。

Now...I created my self-hosted service (this wraps a couple of calls to the 32-bit library for me) like this: 现在...我创建了我的自托管服务(为我包装了对32位库的几个调用),如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Drawing;

namespace SelfHost
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8080/BlahImageWarp");
            Uri mexUri = new Uri("http://localhost:8080/BlahImageWarp/mex");

            // Create the ServiceHost.
            using (ServiceHost host = new ServiceHost(typeof(BlahImageWarpService), baseAddress))
            {
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetUrl = mexUri;
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;

                host.Description.Behaviors.Add(smb);

                host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

                BasicHttpBinding binding = new BasicHttpBinding();
                binding.MaxReceivedMessageSize = int.MaxValue;
                binding.Security.Mode = BasicHttpSecurityMode.None;

                host.AddServiceEndpoint(typeof(IBlahImageWarpService), binding, "");
                // Enable metadata publishing.

                var behavior = host.Description.Behaviors.Find<ServiceDebugBehavior>();
                behavior.IncludeExceptionDetailInFaults = true;

                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }
        }
    }

    [ServiceContract]
    public interface IBlahImageWarpService
    {
        [OperationContract]
        string WarpImageJSON(string JSONString);

        [OperationContract]
        string BitmapToBase64(Bitmap bmp);
    }

    public class BlahImageWarpService : IBlahImageWarpService
    {
        /// <summary>
        /// warps the image
        /// </summary>
        /// <param name="JSONString">JSON of a BlahImgObject</param>
        /// <returns>returns base64Encoded warped image</returns>
        public string WarpImageJSON(string JSONString)
        {
            // this would be the call on the service
            BlahImageConverter conv = new BlahImageConverter(JSONString);
            var base64WarpedImage = conv.Warp();
            return base64WarpedImage;
        }

        public string BitmapToBase64(Bitmap bmp)
        {
            return BlahImageConverter.BitmapToBase64(bmp);
        }
    }
}

I run this service and then go to my REST Service project in VS2013 for web. 我运行此服务,然后转到VS2013中的REST Service项目以用于Web。

I add a reference to this service that's running. 我添加了对正在运行的该服务的引用。

I then build my REST service and copy the .dll to my server along with the self-hosted service. 然后,我构建我的REST服务并将.dll与自托管服务一起复制到我的服务器。

I run the self-hosted service. 我运行自托管服务。

From my Android application I make the call to my REST service. 在我的Android应用程序中,我调用了REST服务。 The REST service craps out at this line: REST服务从以下这一行开始:

writeMessage("Creating service reference");
ServiceReference1.BlahImageWarpServiceClient ImgWarpSvc = new ServiceReference1.BlahImageWarpServiceClient();

With the following error message: 出现以下错误消息:

Could not find default endpoint element that references contract 'ServiceReference1.IBlahImageWarpService' in the ServiceModel client configuration section. 在ServiceModel客户端配置部分中找不到引用合同'ServiceReference1.IBlahImageWarpService'的默认终结点元素。 This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. 这可能是因为找不到您的应用程序的配置文件,或者是因为在客户端元素中找不到与该协定匹配的端点元素。

I'm guessing it's another configuration issue? 我猜这是另一个配置问题?

I'm so close to having all of this working. 我是如此接近所有这些工作。 Would appreciate a nudge in the right direction or a solution. 希望能朝正确的方向轻推或解决。

Thanks very much. 非常感谢。

When you call the ServiceReference1.BlahImageWarpServiceClient constructor overload that doesn't take any parameters, WCF will look in the configuration section of the client configuration file for an entry that references that service contract. 当您调用不带任何参数的ServiceReference1.BlahImageWarpServiceClient构造函数重载时,WCF将在客户端配置文件的配置部分中查找引用该服务协定的条目。

You can either add a client config section, or pass Binding and EndpointAddress objects to the constructor. 您可以添加一个客户端配置节,或者将Binding和EndpointAddress对象传递给构造函数。

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8080/BlahImageWarp");

var client = new ServiceReference1.BlahImageWarpServiceClient(binding, address);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM