- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在Visual Studio中编写了一个非常简单的WCF项目:
iBookStore:
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
namespace BookStore
{
[ServiceContract]
public interface IBookStore
{
[OperationContract]
[WebGet]
List<Book> GetBooksList();
[OperationContract]
[WebGet(UriTemplate = "GetBook/{id}")] // The value of UriTemplate defines the name that the
// client should use to turn to the function
Book GetBookById(int id);
[OperationContract]
[WebInvoke(UriTemplate = "AddBook/{name}", Method = "PUT")]
void AddBook(string name);
[OperationContract]
[WebInvoke(UriTemplate = "UpdateBook/{id}/{name}", Method = "POST")]
void UpdateBook(int id, string name);
[OperationContract]
[WebInvoke(UriTemplate = "DeleteBook/{id}", Method = "DELETE")]
void DeleteBook(int id);
}
[DataContract]
public class Book
{
int id;
string name;
[DataMember]
public int ID
{
get { return id; }
set { id = value; }
}
[DataMember]
public string Name
{
get { return name; }
set { name = value; }
}
}
}
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
namespace BookStore
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class BookStoreImpl : IBookStore
{
public void AddBook(string name)
{
using (var db = new BookStoreContext())
{
Book book = new BookStore.Book { Name = name };
db.Books.Add(book);
db.SaveChanges();
}
}
public void DeleteBook(int id)
{
try
{
using (var db = new BookStoreContext())
{
Book book = db.Books.Find(id);
db.Books.Remove(book);
db.SaveChanges();
}
}
catch
{
throw new FaultException("Something went wrong");
}
}
public Book GetBookById(int id)
{
using (var db = new BookStoreContext())
{
return db.Books.Find(id);
}
}
public List<Book> GetBooksList()
{
List<Book> allBooks = new List<Book>();
try
{
using (var db = new BookStoreContext())
{
IEnumerator<Book> booksEnum = db.Books.GetEnumerator();
booksEnum.Reset();
while (booksEnum.MoveNext())
{
allBooks.Add(booksEnum.Current);
}
}
}
catch
{
throw new FaultException("Something went wrong");
}
return allBooks;
}
public void UpdateBook(int id, string name)
{
try
{
using (var db = new BookStoreContext())
{
Book book = db.Books.Find(id);
book.Name = name;
db.SaveChanges();
}
}
catch
{
throw new FaultException("Something went wrong");
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="BookStore.BookStoreImpl">
<endpoint address="http://localhost:8080/bookservice/" binding="wsHttpBinding" contract="BookStore.IBookStore" />
<endpoint address="" behaviorConfiguration="WebBehavior"
binding="webHttpBinding"
contract="BookStore.IBookStore">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<!--
<system.serviceModel>
<services>
<service name="BookStore.BookStoreImpl">
<endpoint address="http://localhost:8080/bookservice"
behaviorConfiguration="restfulBehavior" binding="webHttpBinding"
bindingConfiguration="" contract="BookStore.IBookStore"
/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/bookservice" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
-->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆栈跟踪:
[InvalidOperationException: No protocol binding matches the given address 'http://localhost:8080/bookservice/'. Protocol bindings are configured at the Site level in IIS or WAS configuration.] System.ServiceModel.Activation.HostedAspNetEnvironment.GetBaseUri(String transportScheme, Uri listenUri) +109963 System.ServiceModel.Channels.TransportChannelListener.OnOpening() +13058405 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +265 System.ServiceModel.Channels.DatagramChannelDemuxer2.OnOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout) +445 System.ServiceModel.Channels.SingletonChannelListener
3.OnOpen(TimeSpan超时)+78 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)+61 [InvalidOperationException:契约(Contract)为““SecurityNegotiationContract”“的'http://localhost:8080/bookservice/'处的ChannelDispatcher无法打开其IChannelListener。] System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)+134 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)+136 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.Security.NegotiationTokenAuthenticator 1.OnOpen(TimeSpan timeout) +137 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +21 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308 System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator.Open(TimeSpan timeout) +23 System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen(TimeSpan timeout) +513 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +21 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308 System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout) +86 System.ServiceModel.Channels.SecurityChannelListener
1.OnOpen(TimeSpan超时) +240 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)+61 [InvalidOperationException:位于'http://localhost:8080/bookservice/'处的ChannelDispatcher与契约(Contract)为'“IssueAndRenewSession” '无法打开其IChannelListener。] System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)+134 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时) +136 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnOpen(TimeSpan超时)+129 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时)+21 System.ServiceModel .Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator.Open(TimeSpan超时)+23 System.ServiceModel.Security.SecuritySessionServerSettings.OnOpen(TimeSpan超时)+759 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时)+21 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+308 System.ServiceModel.Security .SecurityListenerSettingsLifetimeManager.Open(TimeSpan超时)+130 System.ServiceModel.Channels.SecurityChannelListener 1.OnOpen(TimeSpan timeout) +240 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308 System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +61[InvalidOperationException: The ChannelDispatcher at 'http://localhost:8080/bookservice/' with contract(s) '"IBookStore"' is unable to open its IChannelListener.] System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +134 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +136 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308 System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +110 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +641[ServiceActivationException: The service '/BookStoreImpl.svc' cannot be activated due to an exception during compilation. The exception message is: The ChannelDispatcher at 'http://localhost:8080/bookservice/' with contract(s) '"IBookStore"' is unable to open its IChannelListener..] System.Runtime.AsyncResult.End(IAsyncResult result) +481507 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174 System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +351314 System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9791593</pre></code> </td> </tr> </table> <br> <hr width=100% size=1 color=silver> <b>Version Information:</b>ÿMicrosoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1586.0 </font> </body></html><!-- [InvalidOperationException]: No protocol binding matches the given address 'http://localhost:8080/bookservice/'. Protocol bindings are configured at the Site level in IIS or WAS configuration. at System.ServiceModel.Activation.HostedAspNetEnvironment.GetBaseUri(String transportScheme, Uri listenUri) at System.ServiceModel.Channels.TransportChannelListener.OnOpening() at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.DatagramChannelDemuxer
2.OnOuterListenerOpen(System.ServiceModel.Channels.SingletonChannelListener 3.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)[InvalidOperationException]: The ChannelDispatcher at 'http://localhost:8080/bookservice/' with contract(s) '"SecurityNegotiationContract"' is unable to open its IChannelListener. at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.NegotiationTokenAuthenticator
1。 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator.Open(TimeSpan超时)在System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen( System.Ser的TimeSpan超时)在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在System.ServiceModel.Security.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan超时)在System.ServiceModel.Channels.SecurityChannelListener1.OnOpen()上的ViceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时) System.ServiceModel.Channels.CommunicationObject.Open处的TimeSpan超时)(System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen处的TimeSpan超时)[InvalidOperationException]:位于http://localhost:8080/bookservice/的ChannelDispatcher契约(Contract)为““IssueAndRenewSession”“的契约(Contract)无法打开其IChannelListener。在System.ServiceModel.Channels.CommunicationObject.Open(在System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在System.ServiceModel.Channels.CommunicationObject.Open (System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnOpen(TimeSpan超时)处的System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)处的(TimeSpan超时) System.ServiceModel.Security.Security.SecuritySessionServerSettings.OnOpen(TimeSpan超时)处的System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)处的.Security.CommunicationObjectSecurityTokenAuthenticator.Open(TimeSpan超时)超时),位于System.ServiceModel.Security.SecurityListenerSettingsLifetimeMa Nager.Open(TimeSpan超时)在System.ServiceModel.Channels.SecurityChannelListener1.OnOpen(TimeSpan超时)在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)[ InvalidOperationException]:位于'http://localhost:8080/bookservice/'且契约(Contract)为'“IBookStore”'的ChannelDispatcher无法打开其IChannelListener。在System.ServiceModel.Channels.CommunicationObject.Open(在System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在System.ServiceModel.Channels.CommunicationObject.Open (System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo,EventTraceActivity eventTraceActivity)在System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath,EventTraceActivity eventTraceActivity)上的(TimeSpan超时)由于编译期间发生异常而无法激活。异常消息是:契约(Contract)为“IBookStore”的“http://localhost:8080/bookservice/”处的ChannelDispatcher无法在System.ServiceModel.Activation处的System.Runtime.AsyncResult.End [TAsyncResult](IAsyncResult)处打开其IChannelListener。 “。位于System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)处System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar)处的HostedHttpRequestAsyncResult.End(IAsyncResult结果)->-。”
最佳答案
好像是WCF托管问题。
WCF服务应在某些主机中运行。它可能是控制台应用程序,ASP.NET应用程序,Windows服务等。
在尝试访问url http://localhost:8080/bookservice/之前,是否已将服务部署为具有指定地址的IIS应用程序?
您很可能只是在Visual Studio中的调试下启动应用程序。在这种情况下,您应该检查是否正确配置了项目URL。
打开“项目”属性的“Web”选项卡。在“项目网址”编辑框中指定了什么地址?
默认情况下,VS将'localhost:some random port'放置在此处,例如:http://localhost:38577/。在您的情况下,从错误中可以看到该端口最有可能是59250
Error: Cannot obtain Metadata from http://localhost:59250/BookStoreImpl.svc
如果是这种情况,并且您希望坚持使用Web.config,则将此值更改为
http://localhost:8080/bookservice/,按“创建虚拟目录”,然后重新启动调试 session 。然后尝试再次访问
GetBooksList
方法。
关于c# - 通过HTTP访问WCF服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41321612/
WCF 服务、WCF RIA 服务和 WCF 数据服务之间有什么区别? 最佳答案 WCF 是一般服务的通信基础设施。 WCF RIA 服务自动生成客户端和服务器代理对象以方便应用程序开发,并依赖 WC
我想在我的 WPF 项目中使用 WCF 服务 (.svc)。, 我正在尝试创建一个服务。但在 Visual Studio 中,我们有“WCF 服务库”和“WCF 服务应用程序”。我两个都试了。 当我们
我正在开发 WCF Web 服务,并使用 WCF 服务应用程序模板来执行此操作。 创建“WCF 服务应用程序”是否满足此要求?与 WCF 服务应用程序相比,创建 WCF 服务库有哪些优势? 最佳答案
我是 WCF 的新手,对 Web 服务进行编码的经验有限。 在工作中,所有面向网络服务的事物都被要求使用 WCF。我需要做的工作涉及查询一个非 WCF Web 服务,该服务显然是用 Java 构建的,
我有一个数据契约(Contract)说用户。它是可序列化的并且可以通过网络传输。我想要一个操作契约(Contract) SaveUser()。我可以将 SaveUser(User user) 作为运营
我一直在开发一个使用 WCF 访问服务器端逻辑和数据库的 WPF 应用程序。 我从一个 WCF 客户端代理对象开始,我反复使用它来调用服务器上的方法。使用代理一段时间后,服务器最终会抛出异常: Sys
不要添加关于不同 WCF 堆栈的另一篇 SO 帖子,但我想在浪费更多开发时间之前确保我朝着正确的方向前进...... 我的场景 - 我们公司有许多 Web 应用程序,它们都访问同一系列的数据库。所有应
我是WCF技术的新手,我想知道RESTful WCF服务和普通WCF服务有什么区别。 RESTful 服务相对于普通 WCF 服务有哪些优势? 谢谢。 最佳答案 REST服务基于HTTP协议(prot
我正在构建的应用程序公开了多个 WCF 服务(A、B)。在内部,它消耗了在我们的内部网络(X、Y)上运行的其他几个 WCF 服务。 使用 WCF 消息日志记录,我希望仅记录我们的服务 A、B 与调用它
我们需要从另一个 WCF 服务调用 WCF 服务。为了测试这一点,我构建了一个示例控制台应用程序来显示一个简单的字符串。设置是: 控制台应用程序 -> WCF 服务 1 -> WCF 服务 2 Con
假设永远不会直接查询数据的情况。 AKA,总会有一些必须发生的过滤逻辑和/或业务逻辑。 什么时候是在 ajax/js 之外使用数据服务的好理由? 请不要访问此页面 http://msdn.micros
我在尝试将所有常规 WCF 调用转换为异步 WCF 调用时遇到问题。我发现我重构了很多代码,但不确定具体该怎么做。我使用了我找到的方法 here但遇到了我需要事情按顺序发生的问题。 private v
我在 IIS 上有一个 WCF 服务,一些 .net Web 应用程序正在使用它。我的任务是编写一个新的 WCF 服务,要求现有的 Web 应用程序可以使用新服务而无需更改它们的 web.config
我正在尝试用外部提供 WSDL 的 WCF 等效服务替换 WSE 服务。 首先,我使用 svcutil 和 wsdl 生成所有服务和客户端类(ATP,我只关心服务实现。)我生成了一个空的 WCF 服务
场景是这样的:有2个WCF Web Services,一个是客户端(WCFClient),一个是服务端(WCFServer),部署在不同的机器上。我需要他们两个之间的证书通信。 在服务器 WCF 上,
我在 Visual Studio 2013 中创建一个 WCF 服务并将其发布到 IIS。我可以在另一个项目中添加服务引用并使用该服务的方法。当我转到 IIS 服务器管理器时,我看到 WCF 激活及其
我是 .net 的新手,对 WCF 知之甚少,如果有任何愚蠢的问题,请耐心等待。我想知道如果我的代码没有显式生成任何线程,WCF 如何处理 SELF-HOST 场景中的同时调用。因此,在阅读了很多关于
我正在为应用程序开发一个面向服务的体系结构,我希望这些服务既可以通过 WCF 公开,也可以通过一个简单的库使用。理想情况下,我想减少重复代码。 从概念上讲,这映射到: Client => WCF Se
我有一个小型测试网络服务来模拟我在现实世界应用程序中注意到的一些奇怪的东西。由于演示显示与应用程序相同的行为,为了简洁起见,我将使用演示。 简而言之,我的服务接口(interface)文件如下所示(您
我首先为我的 WCF 服务启动了我的订阅者,然后继续发布我的发布者的帖子。我的订阅者能够收到帖子。 其次,我关闭了我的第一个订阅者并再次打开它以订阅相同的服务,即所谓的已订阅该服务的第二个订阅者。再一
我是一名优秀的程序员,十分优秀!