PDA

View Full Version : سوال: WCF - مشکل در add service



hamidhws
پنج شنبه 30 دی 1389, 18:24 عصر
با سلام

من یه کلاس و یه اینترفیس و یه wcf service اضافه کردم به این صورت:


Class :

using System.Runtime.Serialization;
namespace SilverlightApplication16.Web
{
[DataContract]
public class Product
{
[DataMember]
public int ProductId { get; set; }
[DataMember]
public string ProductName { get; set; }
}
}

Interface:

using System.Collections.Generic;
using System.ServiceModel;
namespace SilverlightApplication16.Web
{
[ServiceContract]
public interface IProductServiceContract
{
[OperationContract]
List<Product> GetProductsList();
}
}

اینم توی wcf service که اسمش products.svc گذاشتم وارد کردم :

using System.Collections.Generic;
using System.ServiceModel.Activation;
namespace SilverlightApplication16.Web
{
[AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
public class Products : IProductServiceContract
{
public List<Product> GetProductsList()
{
return
new List<Product>
{
new Product
{
ProductId = 1,
ProductName = "CD"
},
new Product
{
ProductId = 2,
ProductName = "DVD"
},
new Product
{
ProductId = 3,
ProductName = "RAM"
}
};
}
}
}

اینم توی قسمت web.conifig:


<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="SilverlightApplication16.Web.Products.customBindin g0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="SilverlightApplication16.Web.Products">
<endpoint address="" binding="customBinding" bindingConfiguration="SilverlightApplication16.Web.Products.customBindin g0"
contract="SilverlightApplication16.Web.Products" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="" binding="basicHttpBinding"
contract="SilverlightApplication16.Web.IProductServiceContra ct" />
</service>
</services>
</system.serviceModel>
</configuration>


اینارو دقیقا روی کتاب آموزشی انجام دادم
در آخر هر وفتی add service میکنم پیدا میکنه اما هرکاری می کنم ادد نمیشه error میده :گریه:



این خطا رو میده :

There was an error downloading 'http://localhost:38886/Products.svc'.
The request failed with the error message:
--
<html>
<head>
<title>The contract name 'SilverlightApplication16.Web.Products' could not be found in the list of contracts implemented by the service 'Products'.</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>

<body bgcolor="white">

<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

<h2> <i>The contract name 'SilverlightApplication16.Web.Products' could not be found in the list of contracts implemented by the service 'Products'.</i> </h2></span>

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

<br><br>

<b> Exception Details: </b>System.InvalidOperationException: The contract name 'SilverlightApplication16.Web.Products' could not be found in the list of contracts implemented by the service 'Products'.<br><br>

<b>Source Error:</b> <br><br>

<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>

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.</code>

</td>
</tr>
</table>

<br>

<b>Stack Trace:</b> <br><br>

<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>

[InvalidOperationException: The contract name 'SilverlightApplication16.Web.Products' could not be found in the list of contracts implemented by the service 'Products'.]
System.ServiceModel.Description.ConfigLoader.Looku pContract(String contractName, String serviceName) +12238705
System.ServiceModel.Description.ConfigLoader.LoadS erviceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress) +12237329
System.ServiceModel.ServiceHostBase.LoadConfigurat ionSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection) +67
System.ServiceModel.ServiceHostBase.ApplyConfigura tion() +108
System.ServiceModel.ServiceHostBase.InitializeDesc ription(UriSchemeKeyedCollection baseAddresses) +192
System.ServiceModel.ServiceHost.InitializeDescript ion(Type serviceType, UriSchemeKeyedCollection baseAddresses) +49
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +151
System.ServiceModel.Activation.ServiceHostFactory. CreateServiceHost(Type serviceType, Uri[] baseAddresses) +30
System.ServiceModel.Activation.ServiceHostFactory. CreateServiceHost(String constructorString, Uri[] baseAddresses) +420
System.ServiceModel.HostingManager.CreateService(S tring normalizedVirtualPath) +1440
System.ServiceModel.HostingManager.ActivateService (String normalizedVirtualPath) +44
System.ServiceModel.HostingManager.EnsureServiceAv ailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/Products.svc' cannot be activated due to an exception during compilation. The exception message is: The contract name 'SilverlightApplication16.Web.Products' could not be found in the list of contracts implemented by the service 'Products'..]
System.Runtime.AsyncResult.End(IAsyncResult result) +679246
System.ServiceModel.Activation.HostedHttpRequestAs yncResult.End(IAsyncResult result) +190
System.ServiceModel.Activation.HostedHttpRequestAs yncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
System.ServiceModel.Activation.HttpHandler.Process Request(HttpContext context) +24
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +75
</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.0.30319.208

</font>

</body>
</html>
<!--
[InvalidOperationException]: The contract name 'SilverlightApplication16.Web.Products' could not be found in the list of contracts implemented by the service 'Products'.
at System.ServiceModel.Description.ConfigLoader.Looku pContract(String contractName, String serviceName)
at System.ServiceModel.Description.ConfigLoader.LoadS erviceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
at System.ServiceModel.ServiceHostBase.LoadConfigurat ionSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
at System.ServiceModel.ServiceHostBase.ApplyConfigura tion()
at System.ServiceModel.ServiceHostBase.InitializeDesc ription(UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost.InitializeDescript ion(Type serviceType, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
at System.ServiceModel.Activation.ServiceHostFactory. CreateServiceHost(Type serviceType, Uri[] baseAddresses)
at System.ServiceModel.Activation.ServiceHostFactory. CreateServiceHost(String constructorString, Uri[] baseAddresses)
at System.ServiceModel.ServiceHostingEnvironment.Host ingManager.CreateService(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.Host ingManager.ActivateService(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.Host ingManager.EnsureServiceAvailable(String normalizedVirtualPath)
[ServiceActivationException]: The service '/Products.svc' cannot be activated due to an exception during compilation. The exception message is: The contract name 'SilverlightApplication16.Web.Products' could not be found in the list of contracts implemented by the service 'Products'..
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAs yncResult.End(IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAs yncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService)
at System.ServiceModel.Activation.HttpHandler.Process Request(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously)
-->
--.
Metadata contains a reference that cannot be resolved: 'http://localhost:38886/Products.svc'.
An error occurred while receiving the HTTP response to http://localhost:38886/Products.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
If the service is defined in the current solution, try building the solution and adding the service reference again.


یکی کمک کنه لطفا:افسرده:

hamidhws
پنج شنبه 30 دی 1389, 22:19 عصر
دوستان کسی نمیدونه مشکل از کجاست؟!

mahdi7s
شنبه 02 بهمن 1389, 18:21 عصر
سلام
در فایل پیکربندی شما contract را Products قرار دادین در حالی که contract شما IProductServiceContract هست
فایل پیکربندی را به شکل زیر تغییر دهید:

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="SilverlightApplication16.Web.Products.customBindin g0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="SilverlightApplication16.Web.Products">
<endpoint address="" binding="customBinding" bindingConfiguration="SilverlightApplication16.Web.Products.customBindin g0"
contract="SilverlightApplication16.Web.IProductServiceContra ct" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="" binding="basicHttpBinding"
contract="SilverlightApplication16.Web.IProductServiceContra ct" />
</service>
</services>
</system.serviceModel>
</configuration>

hamidhws
دوشنبه 04 بهمن 1389, 00:52 صبح
سلام
در فایل پیکربندی شما contract را Products قرار دادین در حالی که contract شما IProductServiceContract هست
فایل پیکربندی را به شکل زیر تغییر دهید:

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="SilverlightApplication16.Web.Products.customBindin g0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="SilverlightApplication16.Web.Products">
<endpoint address="" binding="customBinding" bindingConfiguration="SilverlightApplication16.Web.Products.customBindin g0"
contract="SilverlightApplication16.Web.IProductServiceContra ct" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="" binding="basicHttpBinding"
contract="SilverlightApplication16.Web.IProductServiceContra ct" />
</service>
</services>
</system.serviceModel>
</configuration>


سلام
از پاسخ شما ممنون دوست عزیز
تغییرات رو اعمال کردم اما بازم همون خطا رو میده نمیدونم مشکل از کجاست :(

AftaB66
دوشنبه 04 بهمن 1389, 14:38 عصر
سلام .


<endpoint address="" binding="basicHttpBinding"
contract="SilverlightApplication16.Web.IProductServiceContra ct" />


این خط کد رو در Web Config استفاده نکنین و برش دارین ، احتمالا درست شه ...

hamidhws
دوشنبه 04 بهمن 1389, 18:20 عصر
سلام .

این خط کد رو در Web Config استفاده نکنین و برش دارین ، احتمالا درست شه ...

سلام دوست عزیز
اینکارو هم کردم اما اینبار این خطا رو داد

There was an error downloading 'http://localhost:38886/Products.svc'.
The request failed with an empty response.
Metadata contains a reference that cannot be resolved: 'http://localhost:38886/Products.svc'.
An error occurred while receiving the HTTP response to http://localhost:38886/Products.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
If the service is defined in the current solution, try building the solution and adding the service reference again.

mahdi7s
دوشنبه 04 بهمن 1389, 19:31 عصر
سلام

در ادامه پست اول خودم

آیا بعد از اعمال تغییرات در فایل پیکربندی پ/ر/و/ک/س/ی تولید شده در کلاینت را آپدیت می کنید؟

hamidhws
چهارشنبه 06 بهمن 1389, 22:57 عصر
سلام

در ادامه پست اول خودم

آیا بعد از اعمال تغییرات در فایل پیکربندی پ/ر/و/ک/س/ی تولید شده در کلاینت را آپدیت می کنید؟

سلام دوست عزیز
منظورتون از آپدیت رو متوجه نشدم

mahdi7s
چهارشنبه 06 بهمن 1389, 23:19 عصر
سلام


منظورتون از آپدیت رو متوجه نشدم برای آپدیت کردن در Solution Explorer بر روی پوشه Service References کلیک و روی مرجع تولید شدید داخل آن راست کلیک و Update را بزنید اگر در زمان Update با خطایی مواجه شده کلاینت سرویس را حذف و دوباره اضافه کنید و نتیجه را و احتمالا متن خطا را پست کنید...

موفق باشید