- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个要求,我想要一个通过 REST 提供 PDF 的 WCF 服务库。例如我有一个这样的 url:localhost:8732/service1/reports/ok
我收到一个 PDF 作为回复。它是本地文件系统中的固定文件。这是我当前的代码:
服务.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfJsonRestService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Service1 : IService1
{
public Stream GetReport(string value)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
FileStream f = new FileStream("C:\\invoice.pdf", FileMode.Open);
int length = (int)f.Length;
WebOperationContext.Current.OutgoingResponse.ContentLength = length;
byte[] buffer = new byte[length];
int sum = 0;
int count;
while ((count = f.Read(buffer, sum, length - sum)) > 0)
{
sum += count;
}
f.Close();
return new MemoryStream(buffer);
}
}
}
IService.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfJsonRestService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
// TODO: Add your service operations here
[OperationContract(Action = "*")]
[WebInvoke(Method = "GET", //Este metodo si esta en POST, te dice que metodo no permitido
UriTemplate = "reports/{value}")]
Stream GetReport(string value);
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
// You can add XSD files into the project. After building the project, you can directly use the data types defined there, with the namespace "WcfJsonRestService.ContractType".
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
应用程序配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WcfJsonRestService.Service1">
<endpoint address="http://localhost:8732/service1"
binding="webHttpBinding"
contract="WcfJsonRestService.IService1"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.1" sku=".NETFramework,Version=v4.1"/>
</startup>
</configuration>
请不要注意那个误导性的名称“WcfJsonRestService”,该名称稍后会更改为更合适的名称...
当我在 Visual Studio 2013 中运行它时,一切正常(除了来自 Microsoft WCF 服务主机的警告,它没有找到任何服务元数据)。当我访问http://localhost:8732/service1/somerandomstring pdf由浏览器打开。 (请注意,目前它是我文件系统上的一个固定目录...)
问题是当我尝试 publish 或 host 时。我遵循了几个关于在 IIS 中托管的教程,但没有成功。我应该怎么做才能让它发挥作用?
操作系统:Windows 8.1.NET 框架 4
最佳答案
几天前我偶然发现了这个问题:这是由于缺少处理此类调用所需的处理程序映射。有多种方法可以解决此问题,例如手动执行 ServiceModelReg.exe
控制台命令。我在下面提出的解决方法更为复杂,但它的优点是可以在不更改 Web 服务器的默认行为的情况下解决特定问题,从而避免潜在的副作用。
安装完成后,您应该能够运行 WCF 服务而不会再次出现 404 错误。
有关此特定问题及其解决方法的更多信息,您还可以 read this post在我的博客上。
关于c# - 无法在 IIS 中正确承载 WCF 服务。错误 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32800794/
我能够CreateContainers、ListContainers、ListBlobs,但是当我尝试发出PUT/DELETE请求来上传或时>删除 Azure 存储 blob 中的文件,但发出请求后显
我想验证从浏览器应用程序传递过来的 API 中的不记名 token 。 API 将通过调用 ../userinfo 端点来验证针对 Keycloak 的 token ,如果检查运行正常,则以所需的内容
大家好,我正在关注 azure 的下一个教程: https://learn.microsoft.com/en-us/rest/api/apimanagement/current-ga/subscrip
我们即将开始集成测试我们的 REST API,这些 API 使用 ADAL.js/不记名 token /passport-azure-ad 进行保护。 现在讨论实际问题,在自动化测试中,我将如何获取不
我们即将开始集成测试我们的 REST API,这些 API 使用 ADAL.js/不记名 token /passport-azure-ad 进行保护。 现在讨论实际问题,在自动化测试中,我将如何获取不
我正在尝试通过 Javascript 将授权 token 承载发送到 REST 端点,所以我这样做: $.ajax( { url: 'http://localhost:8080/resourc
我有一个用于 SSO 的 .NET Core IdentityServer (IS),我想用它来对我的 .NET Core(后端)-Angular(客户端)应用程序进行身份验证。我希望在后端有一个 E
我需要为我的 API 发送我的 token 。我将我的 token 保存在 SharedPreferences 中,我可以恢复它。我的 API 需要一个,与 Bearer 但怎么办? 我测试了授权、H
根据RFC6750 -OAuth 2.0授权框架:不记名 token 使用,不记名 token 是: A security token with the property that any party
我们使用 Angular、.Net WebApi 和 Azure 构建多个应用程序。我们一直在做的是通过隐式 oAuth2/OIDC 授权流程通过 Azure AD 保护应用程序。 一切进展顺利,但到
使用 Owin + Oauth2 + Identity2。 我有一个带有默认基本身份验证设置的 web Api,我已对其进行修改。 我的 startup.cs 部分类 public void Conf
我的应用程序有一个自定义窗口设计,这意味着每个窗口都有以下参数集 (XAML):WindowStyle="无"AllowsTransparency="假" 其中一个子窗口需要显示一个 Flash 组件
我们正在开发具有 JWT Bearer 身份验证的 .Net Core 2.1 Web API。应用程序本身将生成并分发要发送到后端的 token 。 虽然我们已启动并运行所有内容,即我们可以从 An
我有带有 OWIN 管道的 ASP.NET 4.5 服务,它发出 OAuth access_token 以换取用户名/密码。该服务从 ng-app 调用,一旦它获得 token ,就会存储在浏览器的本
我有一个使用 Azure Active Directory 的 Java 后端应用程序。我正在使用 oauth2 不记名 token 登录。在后端,我正在搜索并使用 oauth2 属性“preferr
上周我为现有 MVC 应用程序创建了一个 API,现在正在尝试保护 API 并根据需要重新设计 MVC 端安全性。 目前,MVC 应用程序设置为通过 OWIN/OAuth/Identity 使用应用程
背景 我已经实现了 Thinktecture.IdentityServer.V3(openID Connect 之一)。我已将 OAuth2 承载 token 以以下形式返回到我的 javascrip
我不明白为什么这不起作用。我假设这是我忽略的简单事情。所有其他不使用 token 的测试方法都可以正常工作。目前 token 没有过期时间,我可以通过 Postman 很好地使用它。 @Test pu
在使用 passport 和 oauth2orize 实现 oauth2 堆栈时,在这种情况下,问题特别在于使用 oauth2orize jwt 承载。 oauth2orize jwt bearer
我正在我的 .NET Web 应用程序中实现 Web API 2 服务架构。消费请求的客户端是纯 javascript,没有 mvc/asp.net。我正在使用 OWIN 尝试根据本文 OWIN Be
我是一名优秀的程序员,十分优秀!