我的背景如下:我有一個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