[英]WCF Visual Studio 2017 local development
2020 年 3 月 27 日更新
已經 4 天了,我現在已經把我的辦公室牆填滿了。 :)
大問題
如果我更改以下設置,這將僅在本地工作 匿名身份驗證 = 已啟用
有誰知道如何解決這個問題 - IIS Express - Visual Studio 2017
我退出了工作代碼並在本地創建了一個測試,現在我只停留在一個問題上。
身份驗證現在是我的攔截器
我將需要使用設置進行部署,因為我對 DEV 沒有任何控制權 | 坐 | UAT | PROD --- IAAS 或 PAAS - 我只能編碼 CI 和 CD。
我刪除了所有----配置原來的源代碼中沒有這個
我必須注釋掉
MultipleBindingServiceHost.cs 文件
本地主機抱怨 2 個 URL(一旦我修復了代碼中的所有安全漏洞,我將重新訪問。
string rawUrl = ConfigurationManager.AppSettings["tsRawUrl"];
ServiceEndpoint endpoint = AddServiceEndpoint(typeof(ITicketService), httpBinding, baseAddress, new Uri(rawUrl));
endpoint.Behaviors.Add(new WebHttpBehavior());
#if (!DEBUG)
string vanityUrl = ConfigurationManager.AppSettings["tsVanityUrl"];
ServiceEndpoint endpoint2 = AddServiceEndpoint(typeof(ITicketService), httpBinding, baseAddress, new Uri(vanityUrl));
endpoint2.Behaviors.Add(new WebHttpBehavior());
#endif
2020 年 3 月 23 日
過去一周我一直在努力弄清楚 WCF 和本地機器的開發,現在我來stackoverflow尋求社區幫助。
我的任務是支持具有兩個 WCF 服務的應用程序
Web.config appSettings設置如下:
<appSettings>
<add key="tsVanityUrl" value="http://localhost:1574/TicketService.svc" />
<add key="tsRawUrl" value="http://localhost:1574/TicketService.svc" />
<add key="fsVanityUrl" value="http://localhost:1574/FileService.svc" />
<add key="fsRawUrl" value="http://localhost:1574/FileService.svc" />
</appSettings>
web.config system.serviceModel
<system.serviceModel>
<!-- START RBD Additions for Local Development -->
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="TicketBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="FileBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="TicketSystem.TicketService" behaviorConfiguration="TicketBehavior">
<endpoint address="/TicketService.svc"
binding="basicHttpBinding"
contract="TicketSystem.ITicketService"
/>
</service>
<service name="TicketSystem.FileService" behaviorConfiguration="FileBehavior">
<endpoint address="/FileService.svc"
binding="basicHttpBinding"
contract="TicketSystem.IFileService"
/>
</service>
</services>
<!-- END RBD Additions for Local Development -->
</system.serviceModel>
我不斷收到以下錯誤:
無法將該值添加到集合中,因為該集合已包含相同類型的項:“System.ServiceModel.Description.ServiceMetadataBehavior”。 此集合僅支持每種類型的一個實例。 參數名稱:項目
這將我指向MultipleBindingServiceHost.cs文件
protected override void ApplyConfiguration()
{
base.ApplyConfiguration();
ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();
Description.Behaviors.Add(mexBehavior);
WebHttpBinding httpBinding = new WebHttpBinding();
foreach (Uri baseAddress in BaseAddresses)
{
if (baseAddress.Scheme == Uri.UriSchemeHttp)
{
httpBinding.Security.Mode = WebHttpSecurityMode.None;
mexBehavior.HttpGetEnabled = true;
}
else if (baseAddress.Scheme == Uri.UriSchemeHttps)
{
httpBinding.Security.Mode = WebHttpSecurityMode.Transport;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
mexBehavior.HttpsGetEnabled = true;
}
//ServiceEndpoint endpoint = AddServiceEndpoint(typeof(TicketSystem.ITicketService),
// httpBinding,
// baseAddress);
//endpoint.Behaviors.Add(new WebHttpBehavior());
//Fix for 404 Vanity URL Issue
string rawUrl = ConfigurationManager.AppSettings["tsRawUrl"];
ServiceEndpoint endpoint = AddServiceEndpoint(typeof(ITicketService), httpBinding, baseAddress, new Uri(rawUrl));
endpoint.Behaviors.Add(new WebHttpBehavior());
string vanityUrl = ConfigurationManager.AppSettings["tsVanityUrl"];
ServiceEndpoint endpoint2 = AddServiceEndpoint(typeof(ITicketService), httpBinding, baseAddress, new Uri(vanityUrl));
endpoint2.Behaviors.Add(new WebHttpBehavior());
break;
}
}
}
我知道我非常接近並且可能遺漏了一些非常簡單的東西,但是在花了多天時間之后,我必須在 stackoverflow 上發帖以使服務在我的本地機器上運行。
WCF 服務應用程序項目不支持在一個服務宿主中使用多個服務契約。 一個服務項目有一個服務宿主,我們需要在啟動宿主時指定服務實現的類。 因此,不可能在一台主機上托管多個服務合同。 我們可以在控制台/Windows NT 服務應用程序中創建多個主機,以支持多個服務合同。
using (ServiceHost sh = new ServiceHost(typeof(TestService)), sh2 = new ServiceHost(typeof(MyService1)))
{
sh.Opened += delegate
{
Console.WriteLine("service is ready");
};
sh.Closed += delegate
{
Console.WriteLine("service is closed");
};
sh2.Opened += delegate
{
Console.WriteLine("service2 is ready...");
};
sh2.Closed += delegate
{
Console.WriteLine("Service is closed...");
};
sh.Open();
sh2.Open();
Console.ReadLine();
sh.Close();
sh2.Close();
}
如果有什么我可以幫忙的,請隨時告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.