我已经研究过这一天了,现在正在转向您的专家来咨询您的意见。自行托管WCF无配置 - 难以理解设置端点
我有REST服务是主要的IIS托管服务。
此服务需要与32位非托管的.dll接口。为了做到这一点,我正在采取一种常用的方法,即创建一个自己托管的服务并打电话给它。
有了这样的背景,我有一个时间让自己托管的人工作。
这里要说的是作品中的代码:
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8080/theSvc");
Uri mexUri = new Uri("http://localhost:8080/theSvc/mex");
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(ImgService), baseAddress))
{
// var wsHttpBinding = new WSHttpBinding();
// wsHttpBinding.MaxReceivedMessageSize = int.MaxValue;
// host.AddServiceEndpoint(typeof(IImgService), wsHttpBinding, baseAddress);
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetUrl = mexUri;
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
// Open the ServiceHost to start listening for messages. Since
// no endpoints are explicitly configured, the runtime will create
// one endpoint per base address for each service contract implemented
// by the service.
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();
}
}
}
现在...如果我为了增加maxreceivedMessageSize从using语句删除baseAddress取消注释这些行,我再也不能添加到参考服务:
所以更改此设置:
using (ServiceHost host = new ServiceHost(typeof(ImgService), baseAddress))
要这样:
using (ServiceHost host = new ServiceHost(typeof(ImgService)))
,并取消本:
// var wsHttpBinding = new WSHttpBinding();
// wsHttpBinding.MaxReceivedMessageSize = int.MaxValue;
// host.AddServiceEndpoint(typeof(IImgService), wsHttpBinding, baseAddress);
,我收到的错误:
... - >本地主机
There was an error downloading 'http://...:8080/theSvc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 'http://...:8080/theSvc'.
Metadata contains a reference that cannot be resolved: 'http://...:8080/theSvc'.
If the service is defined in the current solution, try building the solution and adding the service reference again.
像其他人说的帖子在这里...我处于困境中。任何帮助真的很感激。
您是否考虑过WCF的替代方法,与简单的HTTP服务相比,这种方法往往比较复杂? – Simone 2014-09-12 19:23:05
如果能够满足我的需求,我会100%满意。 我觉得我和WCF的服务非常接近,如果我能把这个最后的配置部分弄清楚 – tronious 2014-09-12 19:26:38
嗯,你已经被警告过:)真的,我不能帮你,我小心翼翼地避免WCF – Simone 2014-09-12 19:28:48