我想知道是否可以从不是控制器的类中渲染视图。我所看到的一切似乎都在告诉你:你不能。
我想做的是从 WCF Web 服务呈现部分视图,以便将其推送到其他地方。是否可以使用视图引擎来实现这一点?
谢谢!
更新:
我不断收到 HtmlHelper 的参数 null 异常。这是我的代码和堆栈跟踪。我的部分确实名为 TableOfContent.cshtml,位于 /View/Shared 文件夹中。我是否刚开始以不同的方式实例化我的 ViewContext?
HtmlHelper helper = new HtmlHelper(new ViewContext(), viewData);
var a = helper.Partial("TableOfContent");
Run Code Online (Sandbox Code Playgroud)
at System.Web.Mvc.ViewContext..ctor(ControllerContext controllerContext, IView view, ViewDataDictionary viewData, TempDataDictionary tempData, TextWriter writer)
at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName)
at SyncInvokeProcessEvent(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
Run Code Online (Sandbox Code Playgroud) 我正在尝试将旧的 WCF 客户端转换为 dotnet core。我成功地从 wsdl 生成了代理,并一直在尝试配置它们,以便我可以成功调用端点。根据一些谷歌搜索,似乎在 dotnet core 下我需要从代码配置我的 WCF 客户端。
以下是旧应用程序 web.config 中的 WCF 配置部分:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<endpointBehaviors>
<behavior name="clientEndpointCredential">
<clientCredentials>
<clientCertificate storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectName" findValue="CERTNAME" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="OUR_Customer_OUTBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://the-full-url" behaviorConfiguration="clientEndpointCredential" binding="basicHttpBinding" bindingConfiguration="OUR_Customer_OUTBinding" contract="CustomerInterface.OUR_Customer_OUT" name="HTTPS_Port" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在一堆将由应用程序服务器使用的计算机上发布计算服务.计算服务器是有状态的,需要能够执行异步回调,所以我想通过TCP使用每个会话设置.
服务应用程序是使用VS2008中的WCF服务应用程序项目类型构建的.
因为它发生了计算服务机器运行Vista,所以根据我读过的文档,我应该能够使用WAS托管.我正在尝试遵循Microsoft关于此主题的说明:
但是我很早就遇到了麻烦.我应该将.svc文件放在我的应用程序的虚拟目录中.但由于我不使用IIS主机,如何创建虚拟目录?上面的文档对此并不清楚.
此外,当尝试运行允许net.tcp访问我的应用程序的命令时:
%windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/<WCF Application>" /enabledProtocols:net.tcp
Run Code Online (Sandbox Code Playgroud)
我不知道该替换什么<WCF Application>.同样,似乎有一个先前的步骤缺少以"IIS托管式"方式发布服务的地方.
我创建了一个试图使用该服务的测试应用程序.当我单击"添加服务引用"时,它会发现我的服务但无法使用net.tcp连接到它.
有没有人在这里成功进行WAS托管和服务?你有什么指示吗?
更新:我现在尝试使用IIS管理器(右键单击 - >编辑绑定...)将net.tcp绑定添加到网站,但Add ...对话框中可用的唯一协议是http和https.该列表中没有net.tcp.是的,我已经安装了非http激活组件......非常奇怪.
我正在尝试在网站中使用WCF命名管道,并且它失败并出现错误:
没有端点监听net.pipe:// localhost/mypipename可以接受该消息.这通常是由错误的地址或SOAP操作引起的.有关更多详细信息,请参阅InnerException(如果存在).
和InnerException:
The pipe name could not be obtained for net.pipe://localhost/mypipename.
Run Code Online (Sandbox Code Playgroud)
并且有另一个内部异常给出access denied消息.
我的网站正在使用模拟,并环顾互联网,这似乎是相关的,但我不知道如何解决它.
有没有人有任何想法?
谢谢马特
有没有人知道描述WCF中绑定的所有默认设置的文档?了解客户端和服务器端的默认设置会很棒.
如果文档不存在,也许有一种简单的方法可以以编程方式显示绑定的所有当前设置?
例如,如果我在服务器端使用wsHttpBinding有一个端点,我怎么知道默认设置是什么(例如maxReceiveMessageSize,maxDepth,security mode,clientCredentialType等).
谢谢.
我尝试从WCF消息中删除整个SOAP标头,只想离开信封体.任何人都可以告诉我怎么做到这一点?
像这样创建一个WCF消息:
**string response = "Hello World!";
Message msg = Message.CreateMessage(MessageVersion.Soap11, "*", new TextBodyWriter(response));
msg.Headers.Clear();**
Run Code Online (Sandbox Code Playgroud)
发送SOAP消息将是:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<Binary>Hello World!</Binary>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
但我不想要SOAP头元素,我只需要包络体.如何从WCF消息中删除头元素?
我创建了一个WCF 3.5应用程序,其方法名称TestMe如下所示:
[OperationContract]
[WebInvoke(UriTemplate = "/Login", Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
MyDictionary<string, string> TestMe(string param1, string param2);
Run Code Online (Sandbox Code Playgroud)
MyDictionary使用以下链接创建:https://stackoverflow.com/a/7590189/546033
这里的一切都很好.但问题是从以下实现的方法返回数据时:
MyDictionary<string, string> success = new MyDictionary<string, string>();
success["desc"] = "Test";
return success;
Run Code Online (Sandbox Code Playgroud)
它返回以下json:
{"TestMeResult":{"desc":"Test"}}
Run Code Online (Sandbox Code Playgroud)
而我需要的是:
{"success":{"desc":"Test"}}
Run Code Online (Sandbox Code Playgroud)
success对象名称在哪里.有什么办法可以解决这个问题?
我正在使用启用了Ajax的WCF,当我在网络浏览器中打开网址时,我收到此错误.
由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理具有Action'http:// localhost:22219/MobileService.svc/GetProductCategories ' 的消息.这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).
MobileService代码如下
namespace MobileService
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MobileService
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, …Run Code Online (Sandbox Code Playgroud) 这是我的客户端WCF配置文件:
<configuration>
<system.net>
<defaultProxy
enabled="true"
useDefaultCredentials="true">
<proxy
usesystemdefault="False"
bypassonlocal="False"
proxyaddress="http://172.20.20.254:8088/"
/>
</defaultProxy>
</system.net>
<system.serviceModel>
<client>
<endpoint
address="http://172.20.20.100:8080/Demo/text"
binding="customBinding"
bindingConfiguration="text"
contract="DemoService.IDemoService"
behaviorConfiguration="largeObjectGraph_behaviorConfig"
name="text" />
</client>
<!-- Allow To Desrialize Larg Data -->
<behaviors>
<endpointBehaviors>
<behavior name="largeObjectGraph_behaviorConfig">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="text"
closeTimeout="10675199.02:48:05.4775807"
openTimeout="10675199.02:48:05.4775807"
receiveTimeout="10675199.02:48:05.4775807"
sendTimeout="10675199.02:48:05.4775807">
<CustomMessageEncoder
MaxArrayLength="1073741824"
MaxBytesPerRead="1073741824"
MaxDepth="1073741824"
MaxNameTableCharCount="1073741824"
MaxStringContentLength="1073741824" />
<httpTransport
maxBufferPoolSize="1073741824"
maxReceivedMessageSize="1073741824"
maxBufferSize="1073741824" />
</binding>
</customBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="CustomMessageEncoder" type="CustomMessageEncoder.CustomMessageEncodingElement, CustomMessageEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
使用CustomMessageEncoder绑定以压缩和加密消息.
这是问题:我们的局域网中有Proxy-Server [172.20.20.254:8088]. …
我试图使用一个控制台应用程序托管两个服务.但是,当我尝试这样做时,只有一个服务被托管,而另一个服务没有.
Program.cs中:
namespace WWWCFHost
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(WWWCF.Login)))
{
host.Open();
Console.WriteLine("Service1 Started");
}
using (ServiceHost host1 = new ServiceHost(typeof(WWWCF.UserRegistration)))
{
host1.Open();
Console.WriteLine("Service2 Started");
Console.ReadLine();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
App.config中
<configuration>
<system.serviceModel>
<services>
<service name="WWWCF.Login" behaviorConfiguration="WWWCF.mexBehaviour1">
<endpoint address="Login" binding="basicHttpBinding" contract="WWWCF.ILogin">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080"/>
</baseAddresses>
</host>
</service>
<service name="WWWCF.UserRegistration" behaviorConfiguration="WWWCF.mexBehaviour2">
<endpoint address="UserRegistration" binding="basicHttpBinding" contract="WWWCF.IUserRegistration">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8090"/> …Run Code Online (Sandbox Code Playgroud) wcf-binding ×10
wcf ×9
c# ×5
.net ×4
asp.net ×2
wcf-security ×2
.net-core ×1
asp.net-ajax ×1
c#-4.0 ×1
json ×1
named-pipes ×1
net.tcp ×1
soap ×1
was ×1
web-services ×1