我的背景如下:我有一个WCF REST服务,这是消费者将与之通信的主要服务。WCF Rest服务引用另一个应用程序托管的WCF服务。找不到默认端点?
我有一个辅助应用程序托管的WCF服务(不是基于REST的),它公开了一些方法。这第二个是必要的,因为我需要基于REST的服务能够调用一个32位非托管库。现在
...我创造了这样的我自托管服务(该包装了几个电话到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);
}
}
}
我运行这个服务,然后去我REST服务项目VS2013 for web。
我添加了对正在运行的此服务的引用。
然后,我构建了我的REST服务,并将.dll与自托管服务一起复制到我的服务器。
我运行自托管服务。
从我的Android应用程序中,我打电话给我的REST服务。 REST服务这一行胡扯出来:
writeMessage("Creating service reference");
ServiceReference1.BlahImageWarpServiceClient ImgWarpSvc = new ServiceReference1.BlahImageWarpServiceClient();
,出现以下错误信息:
找不到默认终结点元素,在ServiceModel客户端配置 部分引用合同“ServiceReference1.IBlahImageWarpService”。这可能是因为没有为您的应用程序找到配置文件, 或因为在客户端元素中找不到与此合同匹配的端点元素。
我猜这是另一个配置问题?
我非常接近所有这些工作。希望在正确的方向推动或解决方案。
非常感谢。
非常感谢!就是这样。 – tronious 2014-09-12 22:33:47